Structures can contain any other data type, which includes other structures. - CSharp Custom Type

CSharp examples for Custom Type:struct

Description

Structures can contain any other data type, which includes other structures.

Demo Code

struct point
{
   public int x;
   public int y;
}
struct line
{
   public point starting;
   public point ending;
}
class MainClass/*w  w  w . j  a  v a  2 s .  c o  m*/
{
   public static void Main()
   {
      line myLine;
      myLine.starting.x = 1;
      myLine.starting.y = 4;
      myLine.ending.x = 10;
      myLine.ending.y = 11;
      System.Console.WriteLine("Point 1: ({0},{1})", myLine.starting.x, myLine.starting.y);
      System.Console.WriteLine("Point 2: ({0},{1})", myLine.ending.x, myLine.ending.y);
   }
}

Result


Related Tutorials