LINQ in .NET - placement questions
Q.1 Select the correct query that will give only positive numbers. You can refer the given below array. int[] nums = { 1, -2, 3, 0, -4, 5 ,10,20,-3,100,30};
A) var posNumber = from n in nums
where n > 0
select n;
B) var posNumber = from n in nums
where n is positive
select n;
C) var posNumber = from n in nums
where n is positive Int
select n;
D) None of the above.
View Answer / Hide AnswerQ.2 Select the correct query that will give only positive numbers less than 10.A) var posNumber = from n in nums
where n is positive Int and less than 10
select n;
B) var posNums = from n in nums
where n > 0
where n < 10
select n;
C) var posNumber = from n in nums
where n is positive Int and < 10
select n;
D) None of the above.
View Answer / Hide AnswerQ.3 An integer array is given as follows
int[] nums = { 10, -19, 4, 7, 2, -5, 0,100,50 };Select the correct query to find out the sorted number.
A) var sortNums = from n in nums
orderby n
B) var sortNums = from n in nums
sortedby n
select n;
C) var sortNums = from n in nums
orderby n
select n;
D) None of the above.
View Answer / Hide AnswerQ.4 Which namespace is necessary to use LINQ?A) System.Data
B) System.Linq
C) System.Object
D) None of the above.
View Answer / Hide AnswerQ.5 What are different flavors of LINQ?A) LINQ to Objects
B) LINQ to ADO.NET
C) LINQ to XML
D) All of the above.
View Answer / Hide AnswerQ.6 Trace the output of given below code. List<int> numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
IEnumerable<int> query = numbers.Where(num => num > 5 && num < 10);
foreach (var n in query)
{
Console.Write(n+" ");
}
A) 6 7 8 9
B) Compile Time Error
C) Run Time Error
D) None of the above.
View Answer / Hide AnswerQ.7 According to given below statements, choose the correct option. Statement 1: A variable, declared outside the anonymous method can be accessed inside the anonymous method.
Statement 2: A variable, declared inside the anonymous method can’t be accessed outside the anonymous method.
Statement 3: Unsafe code can’t be accessed within an anonymous method.
Statement 4: Unsafe code can be accessed within an anonymous method.
A) Only statement 1 and 2 are correct.
B) Only statement 2 and 3 are correct.
C) Statement 1, 2 and 3 are correct.
D) Only statement 4 is correct.
View Answer / Hide AnswerQ.8 Trace the output of given below code.using System;
class Program
{
delegate int delDemo(int x, int y);
static void Main(string[] args)
{
delDemo d1 = (x, y) => x * y;
delDemo d2 = (x, y) => { return x + y; };
delDemo d3 = delegate(int x, int y) { return x - y; };
int z1 = d1(10, 5);
int z2 = d2(10, 5);
int z3 = d3(10, 5);
Console.WriteLine(z1);
Console.WriteLine(z2);
Console.WriteLine(z3);
}
}
A) 50 15 5
B) 10 5
C) The above program will not compile.
D) None of the above.
View Answer / Hide AnswerQ.9 According to given below statements, choose the correct option. Statement 1: An extension method is defined as static method but it is called like as an instance method.
Statement 2: An extension method first parameter is preceded by the "this" keyword.
Statement 3: An extension method is defined as static method and it is not called like as an instance method.
Statement 4: An extension method first parameter does not preceded by the "this" keyword.
A) Only statement 1 and 2 are correct.
B) Only statement 2 and 3 are correct.
C) Statement 3 and 4 are correct.
D) Only statement 4 is correct.
View Answer / Hide AnswerQ.10 Trace the output of given below code. List<int> data = new List<int> { 10, 20, 30, 40, 50 };
Console.WriteLine(data.Sum());
Console.WriteLine(data.Average());
Console.WriteLine(data.Max());
A) 50 30 150
B) 150 30 50
C) 150 50 30
D) None of the above
View Answer / Hide AnswerQ.11 Trace the output of given below code. List<int> data = new List<int> { 10, 20, 30, 40, 50 };
Console.WriteLine(data.ElementAt(1));
A) 10
B) 20
C) 30
D) 40
View Answer / Hide AnswerQ.12 Trace the output of given below code. List<int> data = new List<int> { 10, 20, 30, 40, 50, 60 };
Console.WriteLine(data.Single(d => d == 10));
Console.WriteLine(data.SingleOrDefault(d => d == 100));
A) 10 100
B) Single.
C) 10 0
D) None of the above.
View Answer / Hide AnswerQ.13 What is the extension of the file, when LINQ to SQL is used?A) .dbml
B) msdb
C) accdb
D) None of the above.
View Answer / Hide AnswerQ.14 According to given below statements, choose the correct option. Statement 1: LINQ query is compiled each and every time while stored procedures re-used the cached execution plan to execute.
Statement 2: LINQ query does not compiled each and every time when program execute
A) Only statement 1 is correct.
B) Only statement 2 is correct.
C) Both statements are correct.
D) None of the statement is correct.
View Answer / Hide AnswerQ.15 Trace the output of given below code. int[] num1 = { 1, 2, 3, 4, 5 };
int[] num2 = { 5, 6, 7, 8, 9, 10 };
IEnumerable<int> union = num1.Union(num2);
IEnumerable<int> intersection = num1.Intersect(num2);
IEnumerable<int> except = num1.Except(num2);
Console.Write("Union= ");
foreach(var U in union)
{
Console.Write("{0} ",U);
}
Console.Write("Intersection= ");
foreach (var I in intersection)
{
Console.Write("{0} ", I);
}
Console.Write("except= ");
foreach (var E in except)
{
Console.Write("{0} ", E);
}
A) Union= 1 2 3 4 5 6 7 8 9 10 Intersection=1 2 3 4 5 except= 1 2 3 4.
B) Union= 1 2 3 4 5 6 7 8 9 10 Intersection= 5 except= 1 2 3 4.
C) Union= 1 2 3 4 5 6 7 8 9 10 Intersection= 5 except= 6 7 8 9 10.
D) None of the above.
View Answer / Hide Answer