PrepAway - Latest Free Exam Questions & Answers

You need to ensure that B_Products contain all of the p…

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?

PrepAway - Latest Free Exam Questions & Answers

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:
Simply select the product items.

2 Comments on “You need to ensure that B_Products contain all of the p…

  1. megawisdom says:

    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

Leave a Reply