PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are developing an application that includes a class named Employee and a generic list
of employees. The following code segment declares the list of employees:
List<Employee> employeesList = new List<Employee>();
You populate the employeesList object with several hundred Employee objects.
The application must display the data for five Employee objects at a time.
You need to create a method that will return the correct number of Employee objects.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Option A

B.
Option B

C.
Option C

D.
Option D

7 Comments on “Which code segment should you use?

  1. Mah says:

    public static IEnumerable Page(IEnumerable source, int page, int pageSize)
    {
    return source.Skip((page – 1) * pageSize).Take(pageSize);
    }

    if page 1 means it skips 0 and take the pageSize
    if page 2 means it skips first page and take the 2nd page.

    B is correct.




    1



    0
  2. George says:

    List listInt = new List();
    > listInt.Add(1);
    > listInt.Add(2);
    > listInt.Add(3);
    > listInt.Add(4);
    > listInt.Add(5);
    > listInt.Add(6);
    > listInt.Add(7);
    > listInt.Add(8);
    > listInt.Add(9);
    > listInt.Add(10);
    > listInt.Add(11);

    public static IEnumerable Page(IEnumerable source, int page, int pageSize)
    . {
    . return source.Skip((page – 1) * pageSize).Take(pageSize);
    . }

    public void Result(T looper) where T : IEnumerable
    . {
    . foreach (var t in looper)
    . Console.WriteLine(t);
    . }

    r = Page(listInt, 1, 5);
    > Result(r);
    1
    2
    3
    4
    5
    > r = Page(listInt, 2, 5);
    . Result(r);
    6
    7
    8
    9
    10




    1



    0

Leave a Reply