LINQ Interview Questions and Answers Part 2

1. ) What is Anonymous Methods?                                                                                            
Anonymous method allow you to handle an event rather having a separate event handler.   Suppose you want to display some message to users at a click of a button ,ypu can handle it in a standard way with a delegate and event handler or you can also perform this action using anonymous method.
There are some points about anonymous method as given below:-

  • You can not have a jump statement,Break,Go to and continue in an anonymous method.
  • If your program contains same functionality more than once ,you should not use anonymous method.
  • You should also not use an unsafe code inside an anonymous method.
2. ) What are benifits of Anonymous Methods?                                                                  
  • Anonymous Methods helps to reduce the codes .
  • No need to define any static event handlers in anonymous method.
3. ) What is Lambda Expression?                                                                                              
Lambda Expression is the extension of the anonymous method.In .NET Framework 3.5 , a new syntax is introduce in anonymous method that is called Lambda expression. Lambda Expression is an anonymous function that can contain expression and statement to create delegates or expression tree types.It uses the Lambda operator (=>).
(Input parameter) => expression;
The Left had side of the Lambda operator specifies the Expression or the statement.

  • Here parentheses are optional if Lambda Expression has only one parameter.
  • If Lambda Expression contains more than one parameter then parentheses and commas  (') are required otherwise program will give error. 
4. ) What are the benefits of Lambda Expression?                                                            
There are some benefits of Lambda Expression in Linq as given below:-
  • The Lambda Expression allows you to declare your method code inline instead of with the delegate function.
  • It has more concise syntax to achieve same goal.
  • The Lambda Expression are very helpful in writing Linq query expression with a very compact and concise way.
5. ) What is Lambda VS Anonymous Method?                                                                     
  • The Lambda Expression is almost similar to anonymous method which was introduced with .NET 2.0.
  • The Lambda Expression provides a more concise and functional syntax for writing the anonymous method. 
  • There are no basic Difference between them.Means Lambda Expression is an anonymous function.
  • In Lambda Expression ,syntax elements are not required,which is automatically managed by the compiler.
6. ) What are different Methods to write LINQ Query?                                                  
  • Query Syntax
  • Method Syntax
  • Mixed Syntax
 7. ) What are quantifiers in Linq?                                                                                            
There are some quantifiers in Linq as given below:-
  • All ( )
  • Contains ( )
  • Any ( )
  • SequenceEqual() 
 8. ) What are different Aggregate operators used in Linq?                                            
There are some aggregate operators used in Linq as given below:-
  • Aggregate
  • Average
  • Count
  • LongCount
  • Min
  • Max
  • Sum
9. ) What are different Join operators used in Linq?                                                        
  • Join
  • GroupJoin
10. ) What are different Ordering operators used in Linq?                                            
  • OrderBy
  • OrderByDescending
  • ThenBy
  • ThenByDescending
  • Reverse


Post a Comment

Powered by Blogger.