Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0568 

Error Message

Structs cannot contain explicit parameterless constructors

Each struct already has a default constructor that initializes the object to zero. Therefore, the constructors that you can create for a struct must take one or more parameters.

The following sample generates CS0568:

// CS0568.cs
public struct ClassY
{
   public int field1;
   public ClassY(){}   // CS0568, cannot have no param constructor
   // Try following instead:
   // public ClassY(int i)
   // {
   //    field1 = i;
   // }
}

public class ClassX
{
   public static void Main()
   {
   }
}

Community Additions

ADD
Show:
© 2014 Microsoft