answersLogoWhite

0

The non static constructors in C# are the ones participate in object creation, while static constructors are for loading class definitions.

The latter one does not create object instance of the class being loaded

Below are the example of both:

public class Dummy {

// static constructor, no modifier to the method

static Dummy() { Console.Write("loading class Dummy");

}

// the default non static constructor, in conjunction with new operator

public Dummy() { Console.Write("creating an instance of Dummy"); }

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

What is the use of a Static Constructor?

Static Constructor - It is a special type of constructor, introduced with C#. It gets called before the creation of the first object of a class(probably at the time of loading an assembly). See example below. Example: public class SomeClass() { static SomeClass() { //Static members may be accessed from here //Code for Initialization } }


Difference between static and non static constructor?

A static constructor is used to do anything you need done before any static methods are called such as static variable initialization. In Java (as in C#) when a static constructor is called is non-deterministic but will always be called before a static method on the same class.


Open fopen create files. How to you create a folderdirectory?

In Visual C++, or C# you can use static method Directory or non-static DirectoryInfo.


How do you invoke the constructor function in c plus plus?

There is no such thing as a constructor function in C++ (constructors have no return value, not even void, and cannot be called like regular functions). Constructors are invoked rather than called directly, either by declaring a static variable of the class type, or via the C++ new operator.


Constructor and destructor invocation in c?

Not possible in C.


Static variable in c?

A static variable in C is one in which the memory is preallocated before the execution unit begins and lasts for the entire program unit.A non-static variable in C will be allocated in the block in which it is contained, and destroyed outside that block.


What is the difference between implicit and explicit call of constructor in c plus plus?

An implicit constructor call will always call the default constructor, whereas explicit constructor calls allow to chose the best constructor and passing of arguments into the constructor.


True or False A C plus plus class constructor cannot return a function value?

True - A C++ constructor cannot return a value.


What is conustrutor?

A constructor is a function in C which has the same name of the class. The constructor can be used to initialize some function.


Is Constructor Can be Private and Protective in c?

question i understand not


What is the use of private constructor in c plus plus?

Private construction prevents objects from the class from being instantiated other than via a static member function of the class, a friend function or a friend class.


What are the reasons for rise of constructor concept in c?

Not sure what you mean by this. C is a not an object-oriented programming (OOP) language, and therefore has no constructor concept. You probably meant C++ but, even so, there is no "rise of constructor concept". Constructors are fundamental to OOP -- they allow you to initialise an object at the point of instantiation.