Using Classes as Data Members - CSharp Custom Type

CSharp examples for Custom Type:class

Description

Using Classes as Data Members

Demo Code

class Point/*  w w  w  .  ja v a 2  s. c  o m*/
{
    public int x;
    public int y;
}
class Line
{
    public Point starting = new Point();
    public Point ending = new Point();
    public double len;
}
class MainClass
{
    public static void Main()
    {
        Line myLine = new Line();
        myLine.starting.x = 1;
        myLine.starting.y = 4;
        myLine.ending.x = 10;
        myLine.ending.y = 11;
        myLine.len = 100;
        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);
        System.Console.WriteLine("Line Length: {0}", myLine.len);
    }
}

Result


Related Tutorials