Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the C# Compiler supply a default constructor for reference types (if one not specified) or does the CLR?

Tags:

c#

.net

clr

I believe (correct me if i am wrong), according to the C# rule for value types, there is no default constructor. The CLR will define the one for zeroing out the field values.

For reference type :

class Test
{

  private string Name;

}

Will the default constructor be supplied by C# or the CLR?

like image 717
user160677 Avatar asked Sep 05 '09 10:09

user160677


1 Answers

In the CLI specification, a constructor is mandatory for non-static classes, so at least a default constructor will be generated by the compiler if you don't specify another constructor.

So the default constructor will be supplied by the C# Compiler for you.

like image 164
Botz3000 Avatar answered Sep 28 '22 06:09

Botz3000