LINQ Interview Questions and Answers Part 4

By
1.) What are partitioning operators ?                                                                                      
The Partitioning operators in LINQ are used to divide an input  sequence into two sections without rearranging the elements and then retrieving the result  set with one of the sections that satisfies the given condition.
There are following clause are used with partitioning  operators.
  • Take
  • Skip
  • TakeWhile
Syntax:-
public static IEnumerable Skip
    (this IEnumerable source, int count);

2.) What are set operators in LINQ ?                                                                                       
The set operators in LING refer to the query operators that produce a result set.The result set based on the presence  or  absence of the equivalent elements that are present within the same clauses used in set operators.

  • Distinct
  • Union
  • Intersect
  • Except
Syntax:-
public static IEnumerable Distinct
    (this IEquatable source1, IEquatable source2);

3.) What are Element operators used in LINQ ?                                                                 
The element operators in LINQ return just one element.
There are some clauses used with LINQ query as given below.
  • ElementAt :- This clause returns the element at a specified index in a collection.
  • First :-This clause returns the first element of the collection.It returns a default value if there is no such element.
  • FirstorDefault :- This clause returns the first element of a collection or the first element that satisfies a given condition.It returns default value if there is no such element.
  • Last :- This clause returns the last element of the collection or the last element or the last element that satisfies the given condition.
  • LastorDefault :-  This clause returns the last element that satisfies the given condition.It returns a default value if there is no matching element.
  • Single :- This clause returns the only element of the collection that satisfies given condition.
  • Single or Default :- This clause returns the only element of the collection that satisfies the given condition.
  Syntax:-
public static S FirstorDefault <S>
    (this IEnumerable<S> source, 
        Function<S,bool> predicate);

4.) What are aggregate operators  in LINQ ?                                                                        
The aggregate operators compute a single value from a collection.
  • Aggregate
  • Average
  • Count
  • Long Count
  • Max
  • Min
  • Sum
Syntax:- 
public static int count <S>
    (this IEnumerable<S> source, 
        Function<S,bool> predicate);

5.) What are conversion operators  in LINQ ?                                                                      
The conversion operators convert a collection to an array .A conversion operator changes the type of input object.
There are different conversion operators as given below:-
  • ToSequence :- This clause simply returns the source argument by changing it to the IEnumerable<T> Collection.
  • ToArray:- This clause enumerates the source sequence and returns an array containing the elements of the sequence.
  • ToDictionary :-This clause lists the source sequence and evaluates the keyselection and elementselector functions for each element to produce the element key and value of the source sequence. 
  • ToLookup:- This clause implement one to many dictionary that maps te key to the sequence of value.
  • OfType:- This clause allocates and returns enumerable object that captures the source argument.
  • Cast :- This clause allocates and returns an enumerable object that captures the source argument.
Syntax:-
public static ListBox <S>ToList<S>
    (this IEnumerable<S> source);

6.) What are Generation operators  in LINQ ?                                                                     
The Generation operators help in creating a new sequence of values.
There are some generation operators used in LINQ as given below:-

  • Empty :- This clause refers to an empty collection.
  • Range:- This clause generates a collection that contains a sequence of numbers.
  • Repeat :- This clause generates a collection that contains at least one repeated value.
Syntax:-
public static IEnumerable <int>Range
    (int start, int count);

7.) What is LINQ to Object and its benefits ?                                                                        
LINQ to Object refers to the use of LINQ queries with any IEnumerable <T> collection directly ,without the use of any intermediate LINQ provider or Interface.
There are some benefits of LINQ to Object as given below:-
  • It helps in filter multiple conditions as they more concise and readable.
  • It gets easily ported to other data sources with little or no modification.
  • It provides powerful filtering ,ordering and grouping capabilities with the use of minimum application code. 
8.) What is LINQPad  ?                                                                                                                 
The LINQPad supports LINQ to SQL ,Entity Framework ,WCF Services and others Technology also.

9.) What is LINQ Insight  ?                                                                                                          
We can use LINQPad as a LINQ Insight. LINQ Insight is an alternative of LINQPad. It is helpful to Viewing of  SQL ,LINQ to Entities, LINQ to SQL ,LINQ to NHibernate etc.

10.) What is LINQ Providers  ?                                                                                                   
A LINQ Provider is a Library which is used to execute query against data source.

0 comments:

Post a Comment

Powered by Blogger.