Parameterless Constructor for a struct in C# 6.0

Posted on Posted in .net, C#.net

In our previous article, we have discussed the new features introduced in C# 6.0. You can go through that here.

In this article,we will discuss:

  • Parameterless Constructor for a struct
  • How to define Parameterless Struct

 

Parameterless Constructor for a struct:

In earlier versions of C#, the structures or struct types were unable to support parameterless constructors explicitly.

In C# 5.0, every struct had a default parameterless constructor that you couldn’t override.

Using the new operator invoked this constructor and all members of the struct were assigned to default values.

In C# 6.0, you can explicitly define a parameterless constructor for a struct, giving non-default values to the members of the struct.

© 2015, www.techkatak.com. All rights reserved.