Select chapter



Basics (5.papers)

Sponsored Links


  

linq questions and answers

1
When var keyword is used?
  1.  var keyword is used if we don’t
     know the return type of
     the query.
  2. var keyword is used when 
    query returns string
  3. var keyword is used
     when query return
     string[] 
  4. All of the above
Show Answer
Share Facebook gmail Twitter
2
 What is the difference between OrderBy() and Sort() 
method over IList?
  1. OrderBy() sorts and gives the view 
    IEnumerable(). But underlying list
     is sorted or not    changed. 
    Sort() modifies the underlying 
    list.
  2. OrderBy will sort based on particular parameter and sort will sort based on all the elements in the list or dataset
  3. Both a and b
  4. None of the above
Show Answer
Share Facebook gmail Twitter
3
 What is the difference between Select() and 
SelectMany()?
  1.  Select() converts one type to another and returns enumerable. SelectMany() flattens the elements and gives a combined list of elements.
    
  2. Select() converts one type to another and returns ToQueryable(). Select Many() flattens the elements and gives a individual list of elements.
  3. Both a and b
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
6
How to get the count of odd numbers in a list. Below numbers is a generic List<int> ?
  1. int oddNumbers=numbers.
    Count(n=>n%4==1)
  2. int oddNumbers=numbers.
    Count(n=>n%2==0)
  3.  int oddNumbers = numbers.
    Count(n => n % 2 == 1);
  4. None of the above
Show Answer
Share Facebook gmail Twitter
7
How to return only the elements of the array
 that are of particalur type?
  1. Using method .OfType<type>()
  2.  Using method .OfType()
  3. Using method .
    GetType<type>()
  4. All of the above
Show Answer
Share Facebook gmail Twitter
8
How to retrieve the second number from an array?
  1. Using method .ElementAt(1)
  2. Using method .
    GetElementAt(1)
  3. Using method .IndexOf(1)
  4. Both a, b & c
Show Answer
Share Facebook gmail Twitter
9
How to retrieve first element in the array?
  1.  Using method .First()
  2. Using method .ElementAt(1)
  3. Using method 
    .GetElementAt(1)
  4. Using method 
    .IndexOf(1)
Show Answer
Share Facebook gmail Twitter
10
How to generate a sequence of numbers 
from 100 to 149?
  1. List.Range(100,50)
  2. List.Range(100,149)
  3. List.Range(100,150).set(-2)
  4. Both a and b
Show Answer
Share Facebook gmail Twitter
11

How  to create one sequence that contains each array's values, one after the other?
  1. var allNumbers=numbersA.
    ToList(numbersB).
  2. var allNumbers = numbersA.
    Concat(numbersB);
  3. bool match=workdsA.
    wordsb.sequnce()
  4. None of the above
Show Answer
Share Facebook gmail Twitter
12
How to sort a list by length?
  1. var sortedList =from w in List orderby
     w.Length select w;
  2. var sortedList=
    List.order(t->t.length);
  3. both a and b
  4. None of the above
Show Answer
Share Facebook gmail Twitter
13
How to get  only the first 3 elements of the array?
  1. var first3Numbers = numbers
    .Take(3);
  2. var first3Numbers=numbers
    .Top(3)
  3. var first3Numbers=
    numbers.First(3)
  4. None of the above
Show Answer
Share Facebook gmail Twitter
14
How  to get all but the first 4 elements of the array?
  1. var allButFirst4Numbers = 
    numbers.Skip(4);
  2. var allButFirst4Numbers=
    numbers.Except(4)
  3. var allButFirst4Numbers.
    numbers.ToList().Remove(4)
  4. None of the above
Show Answer
Share Facebook gmail Twitter
15
How  to get the elements of the 
array starting from the 
first element divisible by 3?
  1. var allButFirst3Numbers = 
    numbers.SkipWhile
    (n => n % 3 != 0);
  2. codingpart@prettyprint 
    var allButFirst3Numbers = numbers.Skip(n => n % 3 != 0);
  3. codingpart@prettyprint 
    var allButFirst3Numbers =
     numbers.DoWhile
    (n => n % 3 != 0);
  4. All of the above
Show Answer
Share Facebook gmail Twitter
16
How to get the elements of the
+C64 array starting from the first element less than its position?
  1. var laterNumbers =
     numbers.SkipWhile((n, index)
     => n >= index);
  2. var laterNumbers = 
    numbers.Skip((n, index)
     => n >= index);
  3. var laterNumbers = 
    numbers.While((n, index)
     => n >= index);
  4. all of the above
Show Answer
Share Facebook gmail Twitter
17
How to get the elements of the array starting from the first element less than its position?

  1. var laterNumbers = numbers.SkipWhile((n, index) => n >= index);
  2. var laterNumbers = numbers.Skip((n, index) => n >= index);
  3. var laterNumbers = numbers.While((n, index) => n >= index);
  4.  all of the above
Show Answer
Share Facebook gmail Twitter
18
 How to produce a sequence of ints one higher than
 those in an existing array of ints?
  1. var numsPlusOne = from n in 
    numbers select n + 1;
  2. var numsPlusOne = from n 
    in numbers select n + 2;
  3. var numsPlusOne = from n 
    in numbers select n + 3;
  4.  All of the above
Show Answer
Share Facebook gmail Twitter
19
How to make a simple query that returns the text 
form of each digit less than 5?
Ex:  int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; 
string[] digits = { "zero", "one", "two", "three", "four",
 "five", "six", "seven", "eight", "nine" };
  1. var lowNums =from n in 
    numbers where n < 5 select digits[n];
  2. codingpart@prettyprint 
    var lowNums=from n in numbers where n<5 select digits[numbers]
  3.  var lowNums=from n in numbers where n<5 select digits[n-1]
  4.   All of the above
Show Answer
Share Facebook gmail Twitter
20
How to produce a sequence of strings representing thetext version of a sequence of ints?
Ex:  int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; 
        string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}
  1. var textNums =from n in 
    numbers select strings[n];
  2. var textNums =from n in 
    numbers select new{strings[n]};
  3. var textNums =from n in numbers select new{n[strings]}
  4. All of the above
Show Answer
Share Facebook gmail Twitter
Read more papers :