# LinQ MCQ Computer Science

50 Questions 30 Mins

### About LinQ

Following are some of the multiple choice questions on the LinQ with answers that will help the students in developing their knowledge.

## LinQ MCQ

### 1. What will be the output of given code snippet?

```class Program
{
static void Main(string[] args)
{
char []chars = {'a', 'b', 'c'};
String s = new String(chars);
String s1 = "abcd";
int len1 = s1.Length;
int len2 = s.Length;
Console.WriteLine(len1 + " " + len2);
Console.ReadLine();
}
}```
• 0, 1, -2, -4, 5
• 1, 3, 0, 5
• 1, 3, 5
• Run time error

### 2. Select the output for 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 > -5 && n < 6
orderby n descending
select n;
Console.Write("The positive values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}```
• Prints nothing code runs successfully
• Run time error
• Arranged in descending order code runs successfully
• Compile time error

### 3. 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 > -5 && n < 6
orderby n descending
select n;
Console.Write("The positive values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}```
• code run successfully prints nothing
• run time error
• Arranged in descending order code runs successfully
• Compile time error

### 4. What will be the output of the given code snippet?

```static void Main(string[] args)
{
string s1 = " Ixg";
string s2 = s1.Insert(3,"i");
string s3 = s2.Insert(5, "o");
for (int i = 0; i < s3.Length; i++)
Console.WriteLine(s3[i]);
Console.ReadLine();
}```
• Ixg
• Ixig
• Ixgo
• Ixigo

### 5. For the given set of codes, which query will work according to the set of code?

```class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
int len = /*_________________ */
Console.WriteLine("The number of positive values in nums: " + len);
Console.ReadLine();
}
}```
• from n in nums where n > 0select n
• from n in nums where n > 0select n.Count()
• (from n in nums where n > 0select n).Count();
• none of the above

### 6. For the given set of code, what does the output represent?

```class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = from n in nums
where n > 0
select n;
int len = posNums.Count();
Console.WriteLine(len);
Console.ReadLine();
}
}```
• Run time error
• Execution of code with printing all numbers
• Execution of code with nothing being printed
• Execution of code with counting total numbers greater than zero

### 7. For the given set of codes, what is the output?

```class Program
{
static void Main(string[] args)
{
string[] strs = { ".com", ".net", "facebook.com", "google.net", "test", "netflix.net", "hsNameD.com" };
var netAddrs = from addr in strs
where addr.Length > 4 && addr.EndsWith(".net",
StringComparison.Ordinal)
select addr;
foreach (var str in netAddrs) Console.WriteLine(str);
Console.ReadLine();
}
}```
• Compile time error
• Run time error
• google.net netflix.net
• none of the above

### 8. Choose the namespace in which Expression trees are encapsulated:

• System.Linq
• System.Linq.Expressions
• System.Text
• System.Collections.Generic

### 9. Choose the wrong statement about the LINQ?

• The main concept behind the linq is query
• linq makes use of foreach loop to execute the query
• It is not required that linq should make use of IEnumerable interface
• none of the above

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

• System.Text
• System.Collections.Generic
• System.Linq
• none of the above

### 11. Can we use linq to query against a DataTable?

• Yes
• No
• Either Yes or No
• None of the above

### 12. Choose the namespace in which the interface IEnumerable is declared?

• System.Collections
• System.Collections.Generic
• Both a & b
• none of the above

### 13. Assume 2 columns named as Product and Category how can be both sorted out based on first by category and then by product name?

• var sortedProds = _db.Products.Orderby(c => c.Category)
• var sortedProds = _db.Products.Orderby(c => c.Category) + ThenBy(n => n.Name)
• var sortedProds = _db.Products.Orderby(c => c.Category) . ThenBy(n => n.Name)
• none of the above

### 14. Which of the following namespace contains the LINQ to XML?

• System.Xml.Linq
• System.Linq;
• System.Xml;
• None of these

### 15. How to access the data in a collection of classes?

• IEnumerator
• For each
• For
• IEnumerable and IEnumerator

• Where
• Select
• Filter
• Condition

• OrderBy
• OrderAgain
• ThenBy
• Swiggy

### 18. What is the criteria for joining data?

• Same array length
• Same array type
• Common Key
• Differing Keys

### 19. What do LINQ queries return results as?

• String
• Reference type
• Value type
• Object

### 20. What is the advantage of Lambda Expression?

• No return type
• No access modifer
• No method name
• All of the above

### 21. What is superceded by Anonymous methods in LINQ?

• Aggregate functions
• Select
• Filtering
• Lambda Expressions

• GroupBy
• OrderBy
• ThenBy
• Zomato

### 23. What can LINQ be used to access?

• Databases and Data Sources
• Only Collections
• Only Databases
• Value Types

### 24. Whose presentation was the best?

• Aweez
• Aweez, of course
• Bruh, don't even ask
• All of above

### Add Your Review

Your email address will not be published.

## Subscribe to Newsletter!

Subscribe to get latest updates and information.