Member Functions : Member Method « Class « C# / CSharp Tutorial






using System;

class Point
{
    public Point(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
    
    // accessor functions
    public int GetX() {
        return(x);
    }
    public int GetY() {
        return(y);
    }
    
    // variables now private
    int x;
    int y;
}

class MainClass
{
    public static void Main()
    {
        Point myPoint = new Point(10, 15);
        Console.WriteLine("myPoint.X {0}", myPoint.GetX());
        Console.WriteLine("myPoint.Y {0}", myPoint.GetY());
    }
}
myPoint.X 10
myPoint.Y 15








7.4.Member Method
7.4.1.Define methods
7.4.2.Member Functions
7.4.3.Nested methods
7.4.4.Return a value from a member method
7.4.5.Define Rectangle class with method to compute the area
7.4.6.Object Class Methods