In .NET, a value type (C# `struct`

) can't have a constructor with no parameters. According to this post this is mandated by the CLI specification. What happens is that for every value-type a default constructor is created (by the compiler?) which initialized all members to zero (or `null`

).

Why is it disallowed to define such a default constructor?

One trivial use is for rational numbers:

```
public struct Rational {
private long numerator;
private long denominator;
public Rational(long num, long denom)
{ /* Todo: Find GCD etc. */ }
public Rational(long num)
{
numerator = num;
denominator = 1;
}
public Rational() // This is not allowed
{
numerator = 0;
denominator = 1;
}
}
```

Using current version of C#, a default Rational is `0/0`

which is not so cool.

**PS**: Will default parameters help solve this for C# 4.0 or will the CLR-defined default constructor be called?

Jon Skeet answered:

To use your example, what would you want to happen when someone did:

`Rational[] fractions = new Rational[1000];`

Should it run through your constructor 1000 times?

Sure it should, that's why I wrote the default constructor in the first place. The CLR should use the *default zeroing* constructor when no explicit default constructor is defined; that way you only pay for what you use. Then if I want a container of 1000 non-default `Rational`

s (and want to optimize away the 1000 constructions) I will use a `List<Rational>`

rather than an array.

This reason, in my mind, is not strong enough to prevent definition of a default constructor.

`Rational()`

invokes the parameterless ctor rather than the`Rational(long num=0, long denom=1)`

. – LaTeX Feb 6 '11 at 15:05which comes with Visual Studio 2015 it will be allowed to write zero-parameter instance constructors for structs. SoC# 6.0`new Rational()`

will invoke the constructor if it exists, however if it does not exist,`new Rational()`

will be equivalent to`default(Rational)`

. In any case you are encouraged to use the syntax`default(Rational)`

when your want the "zero value" of your struct (which is a "bad" number with your proposed design of`Rational`

). The default value for a value type`T`

is always`default(T)`

. So`new Rational[1000]`

will never invoke struct constructors. – Jeppe Stig Nielsen Nov 20 '14 at 9:51`denominator - 1`

inside the struct, so that the default value becomes 0/1 – miniBill Aug 19 '15 at 14:04