class Fraction {
private int _numerator;
private int _denominator;
public Fraction(int numerator, int denominator)
{
this._numerator = numerator;
this._denominator = denominator;
}
public override string ToString()
{
return String.Format("{0}/{1}", _numerator, _denominator);
}
internal class FractionArtist //定义嵌套类
{
public static void Draw(Fraction f)
{
Console.WriteLine("Drawing the numerator:{0}",f._numerator); //嵌套类能访问外部类的成员
Console.WriteLine("Drawing the denominator:{0}",f._denominator);
}
}
}
Fraction f1 = new Fraction(3, 4);
Console.WriteLine("f1:{0}", f1.ToString());
// Fraction.FractionArtist fa=new Fraction.FractionArtist();
Fraction.FractionArtist.Draw(f1 );//来调用嵌套类