Can a "struct" contain parameter-less constructor or default constructor ?

 Posted by Akiii on 6/7/2012 | Category: C# Interview questions | Views: 4011 | Points: 40

No, a "struct " cannot contain a parameter-less constructor or default constructor. The default constructor is implicit for all structures and cannot be overridden. It simply sets all of the fields in the structure to their default values.

For example :-

struct st

public st()


string name;

public st(string name)
{ = name;

Try to compile the above code and you will get an error like below:-

Structs cannot contain explicit parameterless constructors

| Alert Moderator 

Comments or Responses

Login to post response