Fraction struct : Constructor « struct « C# / CSharp Tutorial






using System;

public struct Fraction {

    public Fraction(double _divisor, double _dividend) {
        divisor = _divisor;
        dividend = _dividend;
    }

    public double quotient {
        get {
            return divisor / dividend;
        }
    }

    private double divisor;
    private double dividend;

}

public class Calculate {
    public static void Main() {
        Fraction number = new Fraction(4, 5);
        Console.WriteLine("{0}", number.quotient);
    }
}








6.3.Constructor
6.3.1.Use method to init struct member variables
6.3.2.Struct constructor with parameters
6.3.3.Structs with constructors
6.3.4.Fraction struct