Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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()
{
}
}