Online Training for Asp.net MVC Web Designing Development, MS SQL, Digital Marketing
C# .Net Interview Questions Answers

C# .Net Interview Questions Answers, .Net Framework


C# is a object-oriented programming language developed by Microsoft. C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows use of various high-level languages on different computer platforms and architectures.
Here are some commonly asked C# Interview Questions

C# interview questions

Can you define OOP and the 4 principles of OOP
  • Abstraction
  • Encapsulation
  • Inheritance
  • polymorphism
Learn more about OOP programming in C#
What is Polymorphism, overloading, overriding and virtual?
What is the difference between static polymorphism and dynamic polymorphism?
Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.
Explain about Generics?
Generics are the new feature in the c# 2.0. They introduce the concept of Type parameter. This makes it possible to classes and methods that differs the specification of one or more types until the class or method is declared and used by the code, which will be using it.

We can declare a generic class like this
public class GenericClass
{
void Add(T input) { }
}

We create an instance of the generic class like this
GenericClass< string> list2 = new GenericClass< string>();
Read more about generic

Frequently asked C# Interview Questions Answers

How generic is different from the ArrayList class?
The System.Collection.ArrayList can be used with any objectn, but no type checking is done when objects are passed to methods. You have to manually cast objects back to our type when retrieving; which makes the code harder.
What is an abstract class?
Define Interface & What is the diff. between abstract & interface?
  • A class can implement any number of interfaces but a subclass can at most use only one abstract class.
  • An abstract class can have non-abstract methods (concrete methods) while in case of interface all the methods has to be abstract.
  • An abstract class can’t be used for multiple inheritance while interface can be used as multiple inheritance.
  • An abstract class use constructor while in an interface we don’t have any type of constructor.
  • In an abstract class all data member or functions are private by default while in interface all are public, we can’t change them manually.
  • An abstract class can declare or use any variables while an interface is not allowed to do so.
  • In an abstract class we need to use abstract keyword to declare abstract methods while in an interface we don’t need to use that.
What is the difference between a struct and a class in C#?
Class and struct both are the user defined data type, but they have some difference
Struct Class
1. The struct is value type in C# and it inherits from System.Value Type. 1. The class is reference type in C# and it inherits from the System.Object Type
2. Struct is usually used for smaller amounts of data 2. Classes are usually used for large amounts of data
3. Structure can't be abstract 3. Class can be abstract type
4. Struct can't be inherited to other type 4. Classes can be inherited to other class.
5. Can not create any default constructor. 5. Can create a default constructor
What is a stack, Heap, Value types and Reference types ?
Stack Heap
1. Stack is used for static memory allocation 1. Heap for dynamic memory allocation
2. Stack memory allocated at compiled time, access to this memory is very fast 2. Heap memory are allocated at run time and accessing this memory is a bit slower
3. Stack is value type 3. Heap reference type
// Stack example
int i=10;
// Heap example
Student stu=new Student();
4. Struct, Enum, byte, decimal, double, float, long 4. string , class, interface, object

what is boxing and unboxing?
Boxing is assigning a value type to reference type variable, unboxing is opposite.

//boxing example
int i=100;
object o =i;
//unboxing example
object o=100;
int i =(int)o; //unboxing

What is the difference between ref and out parameters?
Output parameters are similar to reference parameters, except that they transfer data out of the method rather than within method.

Reference parameter copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.
Is C# code is managed or unmanaged code?
C# is managed code because Common language runtime can compile C# code to Intermediate language.
How can we set class to be inherited, but prevent the method from being over-ridden?
Declare the class as public and make the method sealed to prevent it from being overridden.
What is "protected internal"?
Protected Internal variables/methods are accessible within the same assembly and also from the classes that are derived from this parent class.
Learn more about access modifiers and keywords in C#
What is method overloading?
Method overloading is creating multiple methods with the same name with unique signatures in the same class. When we compile, the compiler uses overload resolution to determine any specific method to be invoked.
What is serialization?
When we want to transport an object through network then we have to convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called Serialization. For an object to be serializable, it should implement ISerialize Interface. De-serialization is the reverse process of creating an object from a stream of bytes.
What is encapsulation?
Encapsulation is defined 'as the process of enclosing one or more items within a physical or logical package'. Encapsulation, in object oriented programming methodology, prevents access to implementation details.
What is a enumeration in C#?
An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.

enumeration cannot inherit or cannot pass inheritance, in C# enumerations are value data type.
What is difference between constants and read-only?
Constant variables are declared and initialized at compile time. The value can’t be changed afterwards. Read only is used only when we want to assign the value at run time.
What's the difference between the Copy() and Clone() ?
In Copy(), we copy the whole object with data, in Clone(), we copy only structure without data.
What is namespace in C#?
A namespace is boundary, is designed for keeping all class in a organised way, So that a class names declared in one namespace does not conflict with the same class names declared in another.
What is Reflection in .Net ?
Reflection is functionalities by which we can get metadata information about loaded assemblies.
All class for using Reflection under System.Reflection
System.Reflection
What is Threading?
Threading is collection of process
What is thread pool?
A thread pool is a collection of threads that can be used to perform several tasks in the background.
Once a thread in the pool completes its task, it is returned to a queue of waiting threads, where it can be reused. This reuse enables applications to avoid the cost of creating a new thread for each task.
What is Thread safety?
Thread safety is a technique which manipulates shared data structure in a manner that guarantees the safe execution of a piece of code by the multiple threads at the same time. A code is called thread safe if it is being called from multiple threads concurrently without the breaking of functionalities

Learn more about Threading
Now Let's Learn some Real time C# implementation
Group Training