When you execute the code, you get an exception.
You need to ensure that B_Products contain all of the products that start with the letter “B”.
What should you do?
A. Option A
B. Option B
C. Option C
D. Option D
When you execute the code, you get an exception.
You need to ensure that B_Products contain all of the products that start with the letter “B”.
What should you do?
A. Option A
B. Option B
C. Option C
D. Option D
List products = new List() {
new Product() { Name = “Strawberry” , CategoryId = 1},
new Product() { Name = “Banana” , CategoryId = 1}
};
List B_Products =(from product in products
where (product.Name.StartsWith(“B”))
select product).ToList();
foreach (Product p in B_Products)
{
Console.WriteLine(p.Name);
}
Actualy, non of the answers is correct, as IEnumerable can not be converted to a list through casting
Yep, you are right Bence.
First of all, a List of Products can not be built using those approaches.
As a matter of fact, letter D could be right ,but the question must be like the example below:
var productA = new Fruit() { Name = “Strawberry”};
var productB = new Fruit() { Name = “Banana”, };
// select new {p.Name} produces a anonymous collection of with a string named Name
// replacing it for p.Name, will fix up
var peoples = new List(new Fruit[] { productA, productB });
List fruits = new List(from p in peoples
where p.Name.StartsWith(“B”)
select new { p.Name });
Marcus Vinicius Matias de Arruda