What should you do?

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

microsoft-exams

3 thoughts on “What should you do?

  1. 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);
    }

  2. Actualy, non of the answers is correct, as IEnumerable can not be converted to a list through casting

    1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.