C# is an object-oriented programming language developed by Microsoft. C# code gets compiled into MSIL that further executes on CLR.
What are types in C#?
C# is a strongly-typed language. It means any variable that we define must have a type such as integer, float, decimal, text, etc.
C# mainly categorized data types in two types:
Value types include simple types (such as int, float, bool, and char), enum types, struct types, and Nullable value types.
Reference types include class types, interface types, delegate types, and array types.
Difference between Value types & Reference types in C#?
In C#, these data types are categorized based on how they store their value in the memory.
A data type is a value type if it holds a data value within its own memory space. It means the variables of these data types directly contain values.
Unlike value types, a reference type doesn't store its value directly. Instead, it stores the address where the value is being stored.
Good to know
What is the use of a
finally block in exception handling?
The finally block will execute when the
try/catch block leaves the execution, no matter what condition cause it. It always executes whether the try block terminates normally or terminates due to an exception. The main purpose of finally block is to release the system resources.
Conditions of leaving
try/catch block could be anything including execution of a
return statement, or propagation of an exception out of the
finally block execute if the code throws an error?
finally block always executes, regardless of whether an exception is thrown.
finally block execute if the code returns from the try block without any exception?
finally block is executed however the flow leaves the
try block - whether by reaching the end, returning, or throwing an exception.
What is the difference between
throw preserves the stack trace while
throw ex does not.
If you use
throw ex, original stack trace will be wiped out completely and you will be left with only the stack trace from where you threw the exception. Hence It's recommended to use
throw instead of
What is the difference between Class & Struct in C#?
How Hashtable works internally?
How Hashtable resolves hash collision?
Dictionary vs Hashtable - which one is faster & why?
Stack vs Heap Memory?
Difference between Managed Resources & Unmanaged Resources in .NET?
How does memory management work in .NET?
Explain Gen0, Gen1, Gen2 here, also Stack vs Heap.
How does memory management work for unmanaged resources?
Explain Dispose() vs Finalize()
Explain IDisposable pattern?
Explain how the string is immutable in C#?