Question-1: What is C#?
Answer: C# is a computer programming language developed by Microsoft in 2000. Using C# language we can develop different types of applications such as web applications, mobile applications, windows applications, etc.
Question-2: What are Managed and Unmanaged Code?
Answer:
Managed Code: Code that is written within a framework could be called managed code because our framework will manage application files, memory allocation and deallocation of objects and Code written in the framework is ready to run in CLR
Unmanaged Code: Code written outside the framework could be called as unmanaged code because we need to manage everything in unmanaged code such as memory allocation, garbage collection etc.
Question-3: What are Boxing and Unboxing
Answer: The process of converting a value type to a reference type is known as Boxing. Boxing is an implicit conversion and our compiler can easily do boxing without any error.
The process of converting reference type to value type is known as Unboxing. Unboxing is an explicit conversion because we had to manually convert the reference type to value type.
Question-4: What is the difference between Throw and Throw ex
Answer: Both Throw and Throw ex is used to generate the exception in the program, using only throw which preserves the original exception stack trace whereas using Throw ex will overwrite the exception stack trace and also overwrite the original exception detail.
Using Throw ex we can also manipulate the original exception and can produce our own exception as per our requirement.
Question-5: What is the difference between IEnumerable and IQuerable
Answer:
- IEnumerable is part of Systm.collections namespaces whereas IQuerable is part of System.Linq namespace
- IEnumerable first loads the data into the memory and then performs the action, means IN-Memory where as IQuerable will perform the operation on the server side means OUT-Memory operation.
- IQuerable is suited when we have data over server-side such as querying DB and IEnumerable is suited when we are querying system objects such as Array, List etc
Question-6: Explain the difference between value types and reference types.
Answer: Value Type: In value type variable the actual values of the variables are saved at the memory address. So if the application searches for the value of the variable then it can get it on the actual location of the variable.
Reference Type: In reference type variables the variables hold the memory address of the location where actual variable data is present. So if the application searches for the value of the variable, then instead of the value of the variable it will return the memory address of the location where actual values are stored. CLR does reference type allocation for variables when the data of the variable is large.
Example: Value types are int, decimal, char, etc. Reference types are objects, Array, etc.
Question-7: What is the purpose of the 'var' keyword?
Example: Value types are int, decimal, char, etc. Reference types are objects, Array, etc.
Question-8: What is the difference between const and readonly?
Question-8: Explain the difference between == and .Equals()?
- '==' is a operator that is used to compare two variables. It checks for equality and returns true if values are equal and false if not.
- We can overload the default behavior of the operator by operator overload.
- For the reference type variable, it checks for the reference instead of the actual value and returns true if both variables point to the same memory location.
- '.Equal()' is a method that is used to compare two variables. It checks for equality and returns true if values are equal and false if not.
- We can override the default behavior of the method by method overriding.
- For the reference type variable, it checks for the reference instead of the actual value and returns true if both variables point to the same memory location. But this default behavior can be changed by overriding the method.
0 Comments