Use out : Out : Language Basics C# Examples


C# Examples » Language Basics » Out »

 

Use out









    
using  System;  
  
class  Decompose  {  
  
    public  int  parts(double  n,  out  double  frac)  {  
        int  whole;  
  
        whole  =  (int)  n;  
        frac  =  n  -  whole;  //  pass  fractional  part  back  through  frac  
        return  whole;  //  return  integer  portion  
    }  
}  
    
class  MainClass  {  
    public  static  void  Main()  {      
      Decompose  ob  =  new  Decompose();  
        int  i;  
        double  f;  
  
        i  =  ob.parts(10.125,  out  f);  
  
        Console.WriteLine("Integer  portion  is  "  +  i);  
        Console.WriteLine("Fractional  part  is  "  +  f);  
    }  
}
    
   
  
   



Output

Integer portion is 10
Fractional part is 0.125


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Out