Linq interview questions for experienced

What is PLINQ?

- PLINQ stands for Parallel Language Integrated Query.
- It supports parallel mechanism of LINQ, which means the query will be executed by multiple processors.
- All the LINQ operators are supported by PLINQ as well as query collections by using PLINQ.
- It can also execute multiple LINQ queries at a time and makes use of multiple processors of the computer.
- PLINQ uses parallelism, which enables fast execution of queries.

Which are the rules apply to a variable scope in lambda expressions?

- A variable used in lambda expression won’t be garbage-collected until the delegate that references that variable is out of the scope.
- Variables used in a lambda expression won’t be accessible in the parent method.
- A lambda expression can’t get a ref or out parameter from an containing method.
- The return statement used in a lambda expression won’t return for the enclosing method.
- A lambda expression does not support a goto, break or continue statement who point t outer the body.

What is the difference between the Select clause and SelectMany() method in LINQ?

- In both the Select clause and SelectMany() method a result value will be generated out of the source of values.
- The difference between both of them is in the result set. The Select clause will generate one value for every source value.
- The result value is a collection which is having the same number of elements from the query.
- On the other side, theSelectMany() method generates a single result that has a concatenated from the query.

What are the different implementations of LINQ?

Following are the different implementations of LINQ:

- LINQ to SQL : This component was introduced in .Net framework version 3.5 that gives a run-time mechanism to manipulate relational data as objects.
- LINQ to DataSet : This component facilitates to run simpler and faster query over data which is cached in the DataSet object.
- LINQ to XML : Provides an in-memory XML programming interface.
- LINQ to Objects : It provides the use of LINQ queries with any IEnumerable or IEnumerable(T)collection directly, without the use of an middle LINQ provider or API, like LINQ to SQL or LINQ to XML.

Why var keyword is used and when it is the only way to get query result?

- var is a keyword introduced in C# 3.0. It is used to substitute the type of the variable with a generalized keyword.
- The compiler infers the actual type from the static type of the expression used to initialize the variable.
- It is must to use the var keyword when we deal with the queries which returns anonymous type.
Example.
var results = from t in MyStringData
select new
{
   NoOfLetter = t.Length,
   CapitalString = t.ToUpper()
};

foreach (var result in results)
{
   Console.WriteLine(result.NoOfLetter + " " + result.CapitalString);
}

What are the pros and cons of LINQ (Language-Integrated Query)?

Pros of LINQ:

- LINQ provides the type safety.
- Abstraction is provided by LINQ and thus it enable us to use the concept of multithreading.
- LINQ is easy to deploy as well as it is easy to understand.
- Using .Net debugger we can debug the LINQ code.
- LINQ allow us to use more than more one database together.

Cons of LINQ:

- In LINQ, it is necessary to process the whole query, and therefore it reduces the performance when we have large and complex queries.
- It is generic, while we can use multiple feature of database using stored procedures.
- In the case of any change in queries, we have to recompile and redeploy the assembly.

What is benefit of using LINQ on Dataset?

- The major objective to use LINQ to Dataset is to execute strongly typed queries over Dataset.
- Consider the scenario that you require to merge the results from two Datasets, or you require to take a distinct value from a Dataset, then we can use LINQ.
- Usually we can use the SQL queries to execute on the database to get the Dataset, but we can’t use SQL queries on a Dataset to retrieve a single value, for which use ofADO.NET features is necessary.
- While, in case of LINQ, it supports better dignified way to execute queries on Dataset and gives some new functionalities than ADO.NET.

What is the difference between the Take and Skip clauses?

- The Take clause will give you a predefined number of elements.
- Suppose if you want to return two elements from an array then you can use Take clause.
- The Skip clause will skip the predefined number of elements in the query and returns the remaining elements.
- Suppose if you want to skip first five strings in an array of strings and want to retrieve the remaining string then you can use Skip clause.

Can you tell the advantages of LINQ over stored procedure?

- Debugging – LINQ supports .Net debugger, so we can easily debug a LINQ query using .NET debugger but it is not supported by SQL stored procedure so it is hard to debug the stored procedure.

- Deployment – To deploy stored procedure it is necessary to write one more script to run them, while LINQ will complie by a single DLL statement and so the deployment will be simple.

- Type Safety - As LINQ supports type safety so errors can be type checked in LINQ queries in compile time.
It is better to use LINQ as it enable us to identify the errors while compilation rather than runtime execution.

Which are the language extensions in C# 3.0 useful for LINQ?

- Lambda Expressions: If we want to create a delegate in LINQ then we can use a Lambda expression.

- Anonymous Types: We can use Anonymous types to generate a bunch of read-only properties in a single object in which it is not necessary to define a type first.

- Object Initializers: C# 3.0 supports Object Initializers to create and initialize the objects in s single step.

- Implicitly Typed Variables: To achieve this we can use “var” keyword.
LINQ to SQL questions and answers
Linq to sql interview questions - What is the DataContext class and how is it related to LINQ?, How does LINQ to SQL differ from Entity framework?, How to Update data in LINQ to SQL? Give example.....
20 Silverlight Interview Questions and Answers - Freshers, Experienced
Silverlight interview questions and answers for freshers and experienced, Silverlight online test, Silverlight jobs - Silverlight architecture, Difference between WPF and Silverlight, limitations of using external fonts in Silverlight, how to perform Event handling in silver light, What is Silverlight.js file?
Silverlight architecture
Silverlight architecture - Silver light is a plug-in used for different platforms and browsers. It is designed for offering media experiences...
Post your comment