.Net framework is one of the most widely used application development, and therefore .net framework skills are important in most work roles. .Net Interview Questions & Answers article, I will share with you some of the most frequently asked questions on .Net framework such as C#, ADO .NET, ASP.NET and ASP.Net MVC. This article is the perfect guide for you to learn all concepts related to .Net Framework.
Contents
Define Property in C# ?
Properties are a type of class member, that are exposed to the outside world as a pair of Methods. A Property acts as a wrapper around a field. It is used to assign and read the value from a field by using set and get accessors.
.Net Interview Questions & Answers – Best TOP 10 (Day – 1)
What is Overloading/Static Polymorphism/Compile-time Polymorphism in C# ?
A function works differently based on parameters. A single function can have different nature based on a number of parameters and types of parameters. When methods are created with the same name, but with different signatures it’s called overloading.
Example:
You have a function Add(). It will receive the parameters and print their addition. You can write with same name Add() but the parameter signature must be different.
Method 1 – Add(int a, int b);
Method 2 – Add(int a, int b, int c);
As per the above example, You have only the same function with a different signature.
What is Constructor Overloading in C# .net ?
Constructor Overloading is a technique to create multiple constructors with different sets of parameters and different numbers of parameters.
The same class may behave in different types based on constructors overloading. With one object initialization, it may show a simple string message whereas in the second initialization of an object with different parameters.
public class Student {
public Student() { }
public Student(String Name) { }
}
.Net Interview Questions & Answers – Best TOP 10 (Day – 2)
What is Function Overloading in C# .net ?
In Function overloading, create multiple numbers of functions that can be created for the same class. But the signatures of each function should vary.
A function works differently based on parameters.
A single function can have different nature based on the number of parameters and types of parameters.
What is Operator Overloading in C# .net ?
- The operator function should be a member function of the containing type.
- The operator function must be static.
- The operator function must have the keyword operator followed by the operator to be overridden.
- The arguments of the function are the operands.
- The return value of the function is the result of the operation. .Net Interview
What is Overloading/Dynamic Polymorphism/Run-time Polymorphism in C#?
Override affects virtual method usage. Virtual methods are meant to be re-implemented in derived classes. The override keyword specifies that a method replaces its virtual base method. .Net Interview
As you know Polymorphism is the concept of OOPS which includes method overriding and method overloading. Virtual and Override keywords are used for method overriding and a new keyword is used for method hiding.
class Empoyee
{
public virtual void Name()
{
Console.WriteLine("Empoyee.Name");
}
}
class Emp : Empoyee
{
public override void Name()
{
Console.WriteLine("Emp.Name");
}
}
class Program
{
static void Main()
{
Empoyee e1 = new Emp();
e1.Name();
}
}
o/p- Emp.Name
.Net Interview Questions & Answers – Best TOP 10 (Day – 3)
What is Method Hiding (new keyword) in C#?
As you have seen in the above example the compiler generates the warnings since C# also supports method hiding. For hiding the base class method from the derived class simply declare the derived class method with a new keyword.
What is a Constructor in C#?
Constructor is a special method that gets invoked/called automatically, whenever an object of a given class gets instantiated.
In C#, Constructors are the special types of methods of a class that get executed when its object is created. Constructors are responsible for object initialization and memory allocation of their class. There is always at least one constructor in every class. If you don’t write a constructor in a class, the C# compiler will automatically provide one constructor for that class, called the default/parameterless constructor.
What is a Destructor in C#?
Destructor is a special method that gets invoked/called automatically whenever an object of a given class gets destroyed. The main idea behind using a destructor is to free the memory used by the object. To create a destructor we need to create a method in a class with the same name as the class preceded with ~ operator.
what is the difference between Constructors and Destructors?
Constructors:
Constructors are the special method of a class, that is used when initializes objects. It looks similar to the method but it has the same name as the class. It is created with the same name of the class and notable thing is that it never returns value so you can’t use this method for returning some value. .Net Interview
It should be the same name as the class.
It never returns value so don’t create constructors with the return type.
A class may have several constructors
A constructor may initialize with our without argument.
.Net Interview Questions & Answers – Best TOP 10 (Day – 1)
Destructors:
Destructors are used to removing all the instances of classes and releasing resources. It actually works like a garbage collector. It is useful to use destructor for security reasons as it clears memory by removing all the instances of objects and classes. .Net Interview
- Destructor is used followed by tilde (~) Symbol
- It is only used with class not the structs
- A class can only have one destructor
- It is cannot be overloaded or inherited.
- It cannot be called. It is invoked automatically.
- It does not have parameters.