A simple struct with method : Struct : Struct C# Examples


C# Examples » Struct » Struct »

 

A simple struct with method









    
using  System;

struct  Fraction  {

    public  int  numerator;
    public  int  denominator;

    public  void  Print(  )  {
        Console.WriteLine(  "{0}/{1}",  numerator,  denominator  );
    }
}

public  class  MainClass  {

    public  static  void  Main(  )  {
        Fraction  f;
        f.numerator      =  5;
        f.denominator  =  10;
        f.Print(  );

        Fraction  f2  =  f;
        f.Print(  );

        f2.numerator  =  1;
        f.Print(  );
        f2.Print(  );
    }
}
    
   
  
   



Output

5/10
5/10
5/10
1/10


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Struct
» Struct