.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Constructors in .net?

Posted By: Nagaraju     Posted Date: June 15, 2011    Points:5   Category :C#
Can you please explain Constructor clearly

Static Constructor , Private Constructor, Defualt Constructor

When will we use these constructor and Major difference between these constructors?

Interview quesiton? Pls help

Author: Gowthammanju             
Posted Date: June 16, 2011     Points: 20   
Author: shiv chandra             
Posted Date: June 16, 2011     Points: 20   

Static Constructor : http://msdn.microsoft.com/en-us/library/k9x6w0hc%28v=vs.80%29.aspx
Default Constructor : Constructor without any parameter is called Default Constructor.

Author: Ravi Ranjan Kumar             
Posted Date: June 16, 2011     Points: 20   

Constructor is a special kind of method with class name as method name and gets executed when its (class) object is created.

Default Constructor :- A constructor that takes no parameters is called a default constructor. Default constructors are invoked whenever an object is instantiated by using the new operator and no arguments are provided to new.

public class MsDotNetHeaven
public MsDotNetHeaven()
//A default Constructor

//Class members


Static Constructor :- When we decorate a constructor as static, then it will become a static constructor.
A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed only once. It is called automatically before the first instance is created or any static members are referenced.

public class MsDotNetHeaven
static MsDotNetHeaven()
//A static Constructor
// Can only access static members here.

System.Console.WriteLine("I am a static constructor.");

//Class members


Private Constructor :- A private constructor is a special instance constructor. It is commonly used in classes that contain static members only. If a class has one or more private constructors and no public constructors, then other classes (except nested classes) are not allowed to create instances of this class.

Take a look there-[http://www.codedigest.com/Articles/Framework/193_What_are_constructors_in_CSharp_-_A_Step_Ahead_Series.aspx ] for more details.

Thanks & Regards
Ravi Ranjan Kumar
Author: manish nain             
Posted Date: September 06, 2011     Points: 20   

I things it is the best site for finding the topic

To get more information about constructor Plz Log in


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend