Monday, July 20, 2020

C# Interview Questions and Answers



Q.1 What is C#.?



Q.2 IEnumerable Vs IQueryable In LINQ.?

Ans:- 
In LINQ to query data from database and collections, we use IEnumerable and IQueryable for data manipulation. IEnumerable is inherited by IQueryable, Hence IQueryable has all the features of IEnumerable and except this, it has its own features. Both have their own importance to query data and data manipulation. Let’s see both the features and take advantage of both the features to boost your LINQ Query performance.

IEnumerable

IEnumerable exists in System. Collections Namespace.

IEnumerable can move forward only over a collection, it can’t move backward and between the items.

IEnumerable is best to query data from in-memory collections like List, Array, etc.

While query data from a database, IEnumerable execute a select query on the server-side, load data in-memory on a client-side, and then filter data.

IEnumerable is suitable for LINQ to Object and LINQ to XML queries.

IEnumerable supports deferred execution.

IEnumerable doesn’t support custom queries.

IEnumerable doesn’t support lazy loading. Hence not suitable for paging like scenarios.

Extension methods support by IEnumerable takes functional objects.

IEnumerable Example
 MyDataContext dc = new MyDataContext ();
IEnumerable<Employee> list = dc.Employees.Where(p => p.Name.StartsWith("S"));
list = list.Take<Employee>(10); 
Generated SQL statements of the above query will be:
 SELECT [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0]
WHERE [t0].[EmpName] LIKE @p0
 Notice that in this query "top 10" is missing since IEnumerable filters records on the client-side


IQueryable

IQueryable exists in System. Linq Namespace.

IQueryable can move forward only over a collection, it can’t move backward and between the items.

IQueryable is best to query data from out-memory (like remote database, service) collections.

While query data from a database, IQueryable execute the select query on the server side with all filters.

IQueryable is suitable for LINQ to SQL queries.

IQueryable supports deferred execution.

IQueryable supports custom query using CreateQuery and Execute methods.

IQueryable support lazy loading. Hence it is suitable for paging like scenarios.

Extension methods support by IQueryable take expression objects means expression tree.
IQueryable Example
 MyDataContext dc = new MyDataContext ();
IQueryable<Employee> list = dc.Employees.Where(p => p.Name.StartsWith("S"));
list = list.Take<Employee>(10); 
Generated SQL statements of the above query will be:
 SELECT TOP 10 [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0]
WHERE [t0].[EmpName] LIKE @p0
Notice that in this query "top 10" is exist since IQueryable executes a query in SQL server with all filters.


Q.3 Difference between IEnumerable and IEnumerator.?

Q2: What is the difference between "continue" and "break" statements in C#.?

Q3: What is Managed or Unmanaged Code?

Q4: What is Boxing and Unboxing?

Q5: What is the difference between a struct and a class in C#?

Q6: Define Property in C#?

Q7: Why can't you specify the accessibility modifier for methods inside the interface?

Q8: How is Exception Handling implemented in C#?

Q9: Can you return multiple values from a function in C#?

Q10: What is namespace in C#?

Q11: What are dynamic type variables in C#?

Q12: Why to use “finally” block in C#?

Q13: What is the difference between Interface and Abstract Class?

Q14: What is the difference between ref and out keywords?

Q15: What is delegates in C# and uses of delegates?

Q16: What is the difference between overloading and overriding?

Q17: Explain Anonymous type in C#

Q18: What is difference between constants and readonly?

Q19: What is a Destructor in C#?

Q20: How encapsulation is implemented in C#?

Q21: What is the output of the program below? Explain your answer.

Q22: Refactor the code

Q23: What is lambda expressions in C#?

Q24: What is marshalling and why do we need it?

Q25: What is difference between late binding and early binding in C#?

Q26: What is an Object Pool in .Net?

Q27: Describe the accessibility modifier "protected internal".

Q28: What are pointer types in C#?

Q29: What is the use of conditional preprocessor directive in C#?

Q30: Can we have only “try” block without “catch” block in C#?

Q31: Why to use lock statement in C#?

Q32: What is the output of the short program below? Explain your answer.

Q33: What is the output of the program below? Explain your answer.

Q34: What is the output of the program below?

Q35: What is the "yield" keyword used for in C#?

Q36: What interface should your data structure implement to make the "Where" method work?

Q37: What is jagged array in C#.Net and when to prefer jagged arrays over multi-dimensional arrays?

Q38: What is a preprocessor directives in C#?

Q39: What are the benefits of a Deferred Execution in LINQ?


Q40 Difference Between Namespace and Assembly.?

No comments:

Post a Comment

Rewrite whole Web Site System and Sub System with data migration to new system.

Can you please share me your skype id or whats up number for better communications  my skype id is - jitendra.tech  whats up - +919617741414...