Saturday, October 17, 2015

Constructors and Destructors

Constructors:
1. Constructor is a special method of a class which will invoke automatically whenever instance or object of class is created.
2. It can't return any value
3. C# supports overloading of constructors
4. You can always make a call to one constructor from within another.
5. There can be only one static constructor in the class.
6. The static constructor should be without parameters and  it can only access the static members of the class.
7. There should be no access modifier in static constructor definition.
8. In inheritance base class constructor get called first.
9. It is mandatory to have the constructor in the class.
10. In case if we do not write constructor, the compiler will try to supply the no parameter constructor for your class.
11. We can neither create the object of the class, nor can we inherit the class with only private constructors.
12. We access static members from the non-static (normal) constructors,there is no such restriction on non-static constructors. But there is one on static constructors that it can access only static members.

Destructors:
1. A destructor is a member that implements the actions required to destruct an instance of a class.
2. A class can only have one destructor.
3. Destructors cannot be inherited or overloaded.
4. Destructors cannot be called. They are invoked automatically. 
5. A destructor does not take modifiers or have parameters.

2 comments:

  1. Dotnetmastery.com is one of the best and ultimate learning recourses for .NET developers. At our website you can learn lots of E-courses in affordable prices. What our Dot Net Mastery courses offering Job focused Training, Fast Track Learning and much. Visit us today at our official website and get best courses today.

    learn .net core MVC

    ReplyDelete
  2. Thanks admin for the post, Its really a nice post and Looking for more blogs like this. Please stay updated..!

    food darzee price

    ReplyDelete