C# struct

(1) struct either do not declare the constructor (there will be a default no-argument constructor), there is either a statement argument constructor, struct statement does not support the display of no-argument constructor.

(2) struct constructor support overloading.

(3) all internal constructor a struct must be assigned to all the fields and attributes.

(4) before method struct you must have assigned values ​​over all fields.

struct ValPoint
{
    public int x;
    public int y;
    public ValPoint(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
}
ValPoint vp;
vp.x = 1;
vp.y = 2;
ValPoint vp = new ValPoint();

 

Guess you like

Origin www.cnblogs.com/liliuwei/p/11271338.html