Question
C# questions: What type of methods can be called without instantiating an object first? static dynamic primary Assume an extension method is defined as: static
C# questions:
What type of methods can be called without instantiating an object first?
static |
dynamic |
primary |
Assume an extension method is defined as:
static class Util
{ public static int Negate(this int i)
{
return -i;
}
}
Which of the following is correct?
int x = 591; Console.WriteLine($"x.Negate {x.Negate()}"); |
int x = 591; Console.WriteLine($"x.Negate {Util.Negate(x)}"); |
both A and B |
None of the above |
To define an extension method for a type:
The extension method can be an instance method |
The first parameter must be of the type being extended |
The first parameter must be proceeded by this keyword |
Both A, B and C |
Both B and C |
Both A and C |
var addresses = new[] {
new { CompanyName = "Alpine Ski House", City = "Berne", Country = "Switzerland"},
new { CompanyName = "Coho Winery", City = "San Francisco", Country = "United States"},
new { CompanyName = "Wingtip Toys", City = "London", Country = "United Kingdom"},
new { CompanyName = "Wide World Importers", City = "Tetbury", Country = "United Kingdom"}
};
var usCompanies =
addresses.Where(addr => String.Equals(addr.Country, "United States"))
.Select(usComp => usComp.CompanyName)
What type is variable usCompanies?
int |
string |
IEnumerable |
anonymous type |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started