Get to know Structs - CSharp Custom Type

CSharp examples for Custom Type:struct

Introduction

A struct is a value type, whereas a class is a reference type.

A struct does not support inheritance.

A struct is implicitly deriving from System.ValueType.

A struct can have all the members a class can, except the following:

  • A parameterless constructor
  • Field initializers
  • A finalizer
  • Virtual or protected members
Point p1 = new Point ();       // p1.x and p1.y will be 0
Point p2 = new Point (1, 1);   // p1.x and p1.y will be 1


public struct Point
{
  int x, y;
  public Point (int x, int y) { this.x = x; this.y = y; }
}

Related Tutorials