LINQ Test: Instructions: Write One Liner Comment Why You Think About That Answer From MCQ
LINQ Test: Instructions: Write One Liner Comment Why You Think About That Answer From MCQ
Instructions: Write one liner comment why you think about that answer from MCQ.
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.
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
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
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();
}
}
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
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
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
1. Anonymous function
2. Can be used to create delegates
3. Named function
4. None
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. DataSet
b. List<T>
c. Array
d. All of the above
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?
b. 1,2,3
c. 1,3,4
d. None of the above
a. Skip
b. Take
c. Where
d. Select
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);
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)
}
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
42. The following code is used will perform _________ operation in LINQ.
a) update
b) select
c) insert
d) all of the mentioned
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
)
44. Which of the following sample code is used to select data Using LinQ To SQL?
a)
b)
45. Which of the following code snippet would traverse through all result objects ?
a)
b)
c)