A list of top frequently asked C# interview questions and answers are given below.
C# is a simple, modern, general purpose programming language. It is an object oriented programming language developed by Microsoft. It is a safe and managed language that is compiled by .NET framework to generate Microsoft intermediate language (machine code).
C# is designed for Common Language Infrastructure (CLI). It contains the executable code and runtime environment that makes the users able to use various high-level languages on different computer platforms and architectures.
These are top reasons to use C# language:
– You can access public declared variables anywhere in the application.
– Static declared variables are globally accessible without creating an instance of the class.
– Void is a type modifier that specifies that the method doesn't return any value.
A constructor is a member function in the class and has the same name as its class. Whenever the object class is created, the constructor is automatically invoked. It constructs the value of data members while initializing the class.
Basically, there are 5 types of constructors:
Static constructor is used to initialize static data members as soon as the class is referenced first time.
Method overloading is mechanism to create multiple methods with the same name and unique signature in the same class. When you go for compilation, the compiler uses overload resolution to determine the specific method to be invoked.
No
Array is a set of related instances either value or reference types.
– There are 3 types of array supported by C#:
ArrayList is a dynamic array. You can add and remove the elements from an ArrayList at runtime. In the ArrayList, elements are not automatically sorted.
A collection works as a container for instances of other classes. All classes implement ICollection interface.
Interface is an abstract class that has only public abstract method. These methods only have declaration not the definition. These abstract methods must be implemented in the inherited classes.
Lock statement is used to ensure that one thread doesn't 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.
If you want to transport an object through network then you have to convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called serialization.
int m_PersonID = 0;
public int PersonID
{
get { return m_PersonID; }
set { m_PersonID = value; }
}
Early binding and late binding are the concept of polymorphism. There are 2 types of polymorphism in C#:
Following are the access modifiers generally used for accessibility:
Abstract class can have abstract and concrete methods whereas interface has only abstract methods.
– The dispose()
method is explicitly called by user to free unmanaged resources such as files, database connections etc whereas finalize()
method is implicitly called by garbage collector to free unmanaged resources like files, database connections etc.
– The dispose()
method belongs to IDisposable interface whereas finalize()
method belongs the Object class.
– Method parameters must be different in method overloading whereas it must be same in method overriding.
– Inheritance is not required in method overloading, it occurs within the same class. But inheritance is required in method overriding.
Object pool is a container of ready to use objects. It reduces the overhead of creating new object.
A delegate in C# is an object that holds the reference to a method. It is like function pointer in C++.
A Hashtable is a collection of key/value pairs. It contains values based on the key.
Reflection allows us to get metadata and assemblies of an object at runtime.
Garbage Collection is a process of releasing memory automatically occupied by objects which are no longer accessible.
All Comments