String format : String Format : String C# Examples


C# Examples » String » String Format »

 

String format









    
using  System;    
    
class  MainClass  {    
    public  static  void  Main()  {    
        int  sum  =  0,  prod  =  1;
        for(int  i=1;  i  <=  10;  i++)  {  
            sum  +=  i;  
            prod  *=  i;  
            string  str  =  String.Format("Sum:{0,3:D}    Product:{1,8:D}",  
                                                    sum,  prod);  
            Console.WriteLine(str);  
        }  
    }  
}
    
   
  
   



Output

Sum:  1  Product:       1
Sum:  3  Product:       2
Sum:  6  Product:       6
Sum: 10  Product:      24
Sum: 15  Product:     120
Sum: 21  Product:     720
Sum: 28  Product:    5040
Sum: 36  Product:   40320
Sum: 45  Product:  362880
Sum: 55  Product: 3628800


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String Format