You have the following code. (Line numbers are included for reference only.)
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
Explanation:
Simply select the product items.
Best answer is D, but it won’t compile, but this will:
class Program
{
static void Main(string[] args)
{
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();
Console.ReadKey();
}
class Product
{
public string Name { get; set; }
public int CategoryID { get; set; }
}
}
1
0
The answer is D
1
0