Hello I an lokesh saini today we learn C# Interview Questions and Answers this is very important
for fresher C# student,
Click here C# Interview Questions and Answers
Q.1 what is static constructor.?
Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with keyword. A static constructor does not take access modifiers or have parameters and can't access any nonelastic data member of a class.
Q.2 What is the use of Monitor in C#?
It provides a mechanism that synchronizes access to objects.
The Monitor class controls access to objects by granting a lock for an object to a single thread. Object locks provide the ability to restrict access to a block of code, commonly called a critical section. While a thread owns the lock for an object, no other thread can acquire that lock. You can also use Monitor to ensure that no other thread is allowed to access a section of application code being executed by the lock owner, unless the other thread is executing the code using a different locked object
Q.3 What is lock statement in C#?
Lock ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread attempts to enter a locked code, it will wait, block, until the object is released.
for fresher C# student,
Click here C# Interview Questions and Answers
Q.1 what is static constructor.?
Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with keyword. A static constructor does not take access modifiers or have parameters and can't access any nonelastic data member of a class.
Q.2 What is the use of Monitor in C#?
It provides a mechanism that synchronizes access to objects.
The Monitor class controls access to objects by granting a lock for an object to a single thread. Object locks provide the ability to restrict access to a block of code, commonly called a critical section. While a thread owns the lock for an object, no other thread can acquire that lock. You can also use Monitor to ensure that no other thread is allowed to access a section of application code being executed by the lock owner, unless the other thread is executing the code using a different locked object
Q.3 What is lock statement in C#?
Lock ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread attempts to enter a locked code, it will wait, block, until the object is released.
Q.4 How to loop through all rows of the DataTable.?
You can do this in more than one way but For Each loop is much better than any other way in terms of cleanliness of the code or performance.
ForEach loop foreach (DataRow row in dTable.Rows)
{
yourvariable = row["ColumnName"].ToString();
}
For loop
for (int j = 0; j< dTable.Rows.Count; j++)
{
yourvariable = dTable.Rows[j]["ColumnName"].ToString()l
}
Q.5 What is an Array?
A array is a collection of slimier data type is store the values in index the will be always start with 0 is called array
other definition:- An array is a collection of related instance either value or reference types. Array posses an immutable structure in which the number of dimensions and size of the array are fixed at instantiation
Q.6 C# Supports Single, Mult dimensional and Jagged Array.
Single Dimensional Array: it is sometimes called vector array consists of single row.
Multidimensional Array: are rectangular & consists of rows and columns.
Jagged Array: also consists of rows & columns but in irregular shaped (like row 1 has 3 column and row 2 has 5 column)





