0% found this document useful (0 votes)
576 views14 pages

LINQ Test: Instructions: Write One Liner Comment Why You Think About That Answer From MCQ

The document contains a multiple choice test on LINQ (Language Integrated Query) with 41 questions. LINQ allows querying of data from various data sources using a SQL-like syntax. Some key points covered include: - LINQ supports querying of object collections, XML documents, and Entity Framework among other data sources. - Classes must implement interfaces like IEnumerable or IQueryable to support LINQ querying. - LINQ uses extension methods in System.Linq.Enumerable and System.Linq.Queryable classes. - LINQ supports query and method syntaxes using lambda expressions. - Standard query operators allow union, intersect, except operations on collections.

Uploaded by

Shilpa Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
576 views14 pages

LINQ Test: Instructions: Write One Liner Comment Why You Think About That Answer From MCQ

The document contains a multiple choice test on LINQ (Language Integrated Query) with 41 questions. LINQ allows querying of data from various data sources using a SQL-like syntax. Some key points covered include: - LINQ supports querying of object collections, XML documents, and Entity Framework among other data sources. - Classes must implement interfaces like IEnumerable or IQueryable to support LINQ querying. - LINQ uses extension methods in System.Linq.Enumerable and System.Linq.Queryable classes. - LINQ supports query and method syntaxes using lambda expressions. - Standard query operators allow union, intersect, except operations on collections.

Uploaded by

Shilpa Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

LINQ Test

Instructions: Write one liner comment why you think about that answer from MCQ.

1. The full form of LINQ is _______.


A. Link-List Inner Query
B. Language-Integrated Query
C. Linked-Integrated Query
D. Lazy Integration Query

2. LINQ supports ________ syntax.


A. C# and F#
B. VB and F#
C. C# and VB
D. All of the above

3. Which of the following supports LINQ queries?


A. Object collection
B. XML Document
C. Entity Framework
D. All of the above

4. A class must implement ____________ interface in order to provide


querying facility using LINQ.
A. IEnumerator or IQueryable
B. IEnumerable or IQueryable
C. Enumerable or Queryable
D. None of the above

5. Which of the following statement is TRUE?


A. LINQ API is a bunch of extension methods included in
System.Linq.Enumerable and System.Linq.Queryable class.
B. LINQ API is a bunch of abstract methods included in Enumerable and
Queryable classes.
C. LINQ API is bunch of queries written in C# and VB.
D. None of the above
6. LINQ supports which of the following syntaxes?
A. Query syntax
B. Method syntax
C. All of the above
D. None of the above

7. var teenAgerStudent = from s in studentList


where s.Age > 12 && s.Age < 20
select s;
The above query is an example of ________ syntax.
A. Method syntax
B. Query syntax
C. C#
D. VB

8. var teenAgerStudents = studentList.Where(s => s.Age > 12 && s.Age


< 20).ToList<Student>();
The above query is an example of _______ syntax.
A. Query syntax
B. Method syntax
C. SQL
D. All of the above

9. Which of the following statement is TRUE?


A. The lambda expression is nothing but extension method.
B. The lambda expression is a shorter way of representing anonymous
methods.
C. The lambda expression is a style of representing dynamic types.
D. The lambda expression is nothing but static delegate method.

10. s => s.Age > 12 && s.Age < 20; is an example of _______.
A. Expression tree
B. LINQ query
C. C# condition
D. Lambda expression
11. Lambda expression can be invoked like a delegate.
A. True
B. False
C. Sometime true
D. Sometime false.

12. OrderByDescending is NOT supported in _______.


A. Query syntax
B. Method syntax
C. Lambda expression
D. VB Method syntax.

13. Which of the following standard query operator returns the differences
between the two collections?
A. Distinct
B. Except
C. Intersect
D. Union

14. Which of the following standard query operator returns the unique
elements from two collections?
A. Distinct
B. Except
C. Intersect
D. Union

15. Which of the following standard query operator returns the common
elements from two collections?
A. Distinct
B. Except
C. Except
D. Intersect

16. Expression tree is _________.


A. Tree of expression in C# or VB.
B. Executable tree structure.
C. In-memory representation of lambda expression.
D. Binary tree like data structure for better LINQ support.
17. Which of the following operators executes LINQ query immediately and
gets the result?
A. 'To' operators
B. Casting operators
C. Grouping operators
D. Joining operators

18. What is the difference between First and FirstOrDefault?


A. First throws an exception whereas FirstOrDefault returns default value, if
no elements found for specified criteria.
B. First returns NULL whereas FirstOrDefault returns default value, if no
elements found for specified criteria.
C. First throws an exception whereas FirstOrDefault returns NULL, if no
elements found for specified criteria.
D. First returns void whereas FirstOrDefault returns NULL value, if no
elements found for specified criteria.

19. Third party data providers must implement ________ interface, in order
to support LINQ.
A. IEnumerable
B. IQueryable
C. ICollection
D. IEnumerator

20.  Select the namespace which should be included while making use of LINQ operations:

A. System.Text

B. System.Collections.Generic

C. System.Linq

D. None of the mentioned

21. Select the output for the given code snippet:

class Program
 {
     static void Main(string[] args)
     {
         int[] nums = { 1, -2, 3, 0, -4, 5 };
         var posNums = from n in nums
                       where n % 2 ==0
                       select n;
            Console.Write("The positive values in nums: ");
            foreach (int i in posNums) Console.Write(i + " ");
            Console.WriteLine();
            Console.ReadLine();
    }
  }

A. code run successfully prints nothing

B. run time error

C. code run successfully and executes output

D. compile time error

22.     When do LINQ queries actually run?


a. When they are iterated over in a foreachloop

b. When calling the ToArray() method on the range variable


c. When calling the ToList() method on the range variable
d. All of the above

23.  What types of Objects can you query using LINQ?


a. DataTables and DataSets

b. Any .NET Framework collection that implements IEnumerable(T)


c. Collections that implement interfaces that inherit from IEnumerable(T)
d. All of the above

24. Which of the following statement is correct?


a. Anonymous types are class types that derive directly from object.

b. Anonymous types are not class types that derive directly from object.
c. Anonymous types are class types that derive directly from System.Class.
d. None of the above
25.    Choose the correct one
a. Variables introduced within a lambda expression are not visible in the outer method.

b. Variables introduced within a lambda expression are visible in the outer method.
c. The lambda should not contain the same number of parameters as the delegate type.
d. None of the above

26.  Choose the correct one.

a. The return value of the lambda (if any) must be explicitly convertible to the delegate's
return type
b. Each input parameter in the lambda must be implicitly convertible to its
corresponding delegate parameter.
c. Lamda expression does not work with LINQ.
d. None of the above

27. Choose the correct one


a. The lambda must contain the same number of parameters as the delegate type.

b. The lambda should not contain the same number of parameters as the delegate type.
c. The return value of the lambda (if any) must be explicitly convertible to the delegate's
return type
d. None of the above

28. What is lamda expression?

1. Anonymous function
2. Can  be used to create delegates
3. Named function
4. None

29. Which of the following objects represents a LINQ to SQL O / R map?

a. DataSet
b. XElement
c. ObjectContext
d. DataContext

30. How you can merge the results from two separate LINQ queries into a single
result set.

a. Use the ToList method.


b. Use the DataContractJsonSerializer class.
c. Use the XElement class.
d. Use the Concat method.

31, LINQ query can work with?

a. DataSet
b. List<T>
c. Array
d. All of the above

32. Which of the following statements is true?

a. LINQ to SQL works with any database.


b. LINQ to SQL works with SQL Server.
c. LINQ to SQL is a CLR feature.
d. LINQ to SQL is a SQL Server feature.

33.  Which LINQ keyword is used to categorize results in a query?

a. where
b. select
c. join
d. group

34. Which LINQ statement is used to merge two data sources to perform queries?

a. where
b. select
c. join
d. group
35. What types of shapes can LINQ query results be shaped into?

1. Collections of primitive types


2. Collections of complex types
3. Single types

4. Collections of anonymous types


a. 1, 2, 4

b. 1,2,3
c. 1,3,4
d. None of the above

36. Which query expression is used to limit the number of results?

a. Skip
b. Take
c. Where
d. Select

37. Query alternative to the following SQL code in LINQ is ____________

SELECT TOP 10 UPPER (c1.Name)


FROM Customer c1
WHERE
c1.Name LIKE 'A%'
AND c1.ID NOT IN
(
SELECT TOP 20 c2.ID
FROM Customer c2
WHERE c2.Name LIKE 'A%'
ORDER BY c2.Name
)
ORDER BY c1.Name

a)

var query =
FROM c IN db.Customers
WHERE c.Name.EndsWith ("A")
orderby c.Name
SELECT c.Name.ToUpper();
var thirdPage = query.Skip(20).Take(10);

b)

var query =
FROM c IN db.Customers
WHERE c.Name.StartsWith ("65")
orderby c.Name
SELECT c.Name.ToUpper();
var thirdPage = query.Skip(20).Take(10);

c)

var query =
FROM c IN db.Customers
WHERE c.Name.StartsWith ("A")
orderby c.Name
SELECT c.Name.ToUpper();
var thirdPage = query.Skip(20).Take(10);

d)

var query =
FROM c IN db.Customers
WHERE c.Name.StartsWith ("A")
orderby c.Name
SELECT c.Name.ToLower();
var thirdPage = query.Skip(20).Take(10);

37. Point out the correct statement.


a) LINQ supports flat outer joins
b) LINQ’s parameterization is inline, typesafe, and highly readable
c) LINQ queries are composable
d) All of the mentioned

39 . LINQ query to retrieve a selection of customers, each with their high-value purchases is
_____________

a)

FROM c IN db.Customers
WHERE c.Address.State == "WA"
SELECT NEW
{
c.Name,
c.CustomerNumber,
HighValuePurchases = c.Purchases.Where (p => p.Price > 1000)
}
b)

FROM c IN db.Customers
WHERE c.Address.State = "WA"
SELECT NEW
{
c.Name,
c.CustomerNumber,
HighValuePurchases = c.Purchases.Where (p => p.Price > 1000)
}

c)

FROM c IN db.Customers
WHERE c.Address.State == "WA"
SELECT NEW
{
c.Name,
c.CustomerNumber,
HighValuePurchases != c.Purchases.Where (p => p.Price > 1000)
}

d) All of the mentioned

40. LINQ Query to list all purchases of $1000 or greater made by customers who live in Washington.
a)

FROM p IN db.Purchases
WHERE p.Customer.Address.State == "WA" || p.Customer == NULL
WHERE p.PurchaseItems.Sum (pi => pi.SaleAmount) = 1000
SELECT p

b)

FROM p IN db.Purchases
WHERE p.Customer.Address.State == "WA" || p.Customer == NULL
WHERE p.PurchaseItems.Sum (pi => pi.SaleAmount) < 1000
SELECT p

c)

FROM p IN db.Purchases
WHERE p.Customer.Address.State == "WA" || p.Customer == NULL
WHERE p.PurchaseItems.Sum (pi => pi.SaleAmount) > 1000
SELECT p

d) None of the mentioned


41. Point out the wrong statement.
a) Compared to SQL, LINQ is complex, tidier, and lower-level
b) LINQ supports ad hoc join
c) Another benefit of LINQ is that you can query across relationships without having to join
d) None of the mentioned

42. The following code is used will perform _________ operation in LINQ.

public bool IsValidUser(string userName, string passWord)


{
DBNameDataContext myDB = NEW DBNameDataContext();
List<User> users = myDB.Users.Where(u => u.Username == userName && u.Password==passWord);
IF(users.Count>0)
{
RETURN TRUE;
}
RETURN FALSE;
}

a) update
b) select
c) insert
d) all of the mentioned

43. Query alternative to the following LINQ code in SQL is ____________

FROM p IN db.Purchases
WHERE p.Customer.Address.State == "WA" || p.Customer == NULL
WHERE p.PurchaseItems.Sum (pi => pi.SaleAmount) > 1000
SELECT p

a)

SELECT p.*
FROM Purchase p
LEFT OUTER JOIN
Customer c INNER JOIN Address a ON c.AddressID = a.ID
ON p.CustomerID = c.ID
WHERE
(a.State = 'WA' || p.CustomerID IS NULL)
AND p.ID IN
(
SELECT PurchaseID FROM PurchaseItem
GROUP BY PurchaseID WHERE SUM (SaleAmount) > 1000
)

b)
SELECT p.*
FROM Purchase p
LEFT OUTER JOIN
Customer c INNER JOIN Address a ON c.AddressID = a.ID
ON p.CustomerID = c.ID
WHERE
(a.State = 'WA' || p.CustomerID IS NULL)
AND p.ID IN
(
SELECT PurchaseID FROM PurchaseItem
GROUP BY PurchaseID HAVING SUM (SaleAmount) > 1000
)

c)

SELECT p.*
FROM Purchase p
LEFT OUTER JOIN
Customer c INNER JOIN Address a ON c.AddressID = a.ID
ON p.CustomerID = c.ID
WHERE
(a.State = 'WA' || p.CustomerID IS NULL)
AND p.ID IN
(
SELECT PurchaseID FROM PurchaseItem
GROUP BY PurchaseID HAVING SUM (SaleAmount) < 1000
)

d) None of the mentioned

44. Which of the following sample code is used to select data Using LinQ To SQL?
a)

public bool IsValidUser(string userName, string passWord)


{
DBNameDataContext myDB = NEW DBNameDataContext();
RETURN Enumerable.Count(userResults) > 0;
}

b)

public bool IsValidUser(string userName, string passWord)


{
DBNameDataContext myDB = NEW DBNameDataContext();
var userResults = FROM u IN myDB.Users
WHERE u.Username == userName
&& u.Password == passWord
SELECT u;
RETURN Enumerable.Count(userResults) > 0;
}
c)

public bool IsValidUser(string userName, string passWord)


{
DBNameDataContext myDB = NEW DBNameDataContext();
var userResults = FROM u IN myDB.Users
WHERE u.Username == userName
&& u.Password == passWord
SELECT u;
RETURN Enumerable.Count(userResults) == 0;
}

d) All of the mentioned

45. Which of the following code snippet would traverse through all result objects ?
a)

foreach(USER USER IN userResults)


{
//checking the RESULT AS LIKE object
IF(USER.Role == 'admin')
{
//do whatever you need
}
}

b)

FOR(USER USER IN userResults)


{
//checking the RESULT AS LIKE object
IF(USER.Role == 'admin')
{
//do whatever you need
}
}

c)

While(USER USER IN userResults)


{
//checking the RESULT AS LIKE object
IF(USER.Role == 'admin')
{
//do whatever you need
}
}
d) None of the mentioned

46. LINQ to SQL is considered to be one of Microsoft’s _______ products.


a) ORM
b) ODBC
c) JDBC
d) SQLLIB

47. Write Left Join query in LINQ.

48. Write Right Join query in LINQ.

49. Why to use LINQ?

50. What is difference between First and Single method?

You might also like