Use CultureInfo int ToString method

image_pdfimage_print
   
 


using System;
using System.Globalization;
using System.Threading;

class Program {
    static void Main(string[] args) {
        int val = 1234567890;
        Console.WriteLine(val.ToString("N"));
        Console.WriteLine(val.ToString("N",new CultureInfo("fr-FR")));
        Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
        Console.WriteLine(val.ToString("N"));
    }
}
           
         
     


Using Variables

image_pdfimage_print
   
 
using System;

public class UsingVariables
{
  static void Main(string[] args)
  {
    int MyInt = 12345;
    int MyInt2 = MyInt + 1;
    int MyInt3;

    MyInt3 = My2ndFunction(MyInt2);
  }
  static public int My2ndFunction(int myInt2)
  {
    myInt2 = myInt2 * 2;
    return myInt2;
  }
}

           
         
     


Using Integers

image_pdfimage_print
   
 
using System;

public class UsingIntegers
{
  static void Main(string[] args)
  {
    int MyInt = 12345;
    long MyLong = MyInt;
    
  }

  public long My2ndFunction(long MyLong)
  {
    try
    {
      long c = checked(MyLong * 500);
    }
    catch (OverflowException e)
    {
      Console.WriteLine(e);
    }

    return 0;
  }
}

           
         
     


displays a conversion table of Fahrenheit to Celsius

image_pdfimage_print

/*
This program displays a conversion
table of Fahrenheit to Celsius.

Call this program FtoCTable.cs.
*/

using System;

public class FtoCTable {
public static void Main() {
double f, c;
int counter;

counter = 0;
for(f = 0.0; f < 100.0; f++) { c = 5.0 / 9.0 * (f - 32.0); // convert to Celsius Console.WriteLine(f + " degrees Fahrenheit is " + c + " degrees Celsius."); counter++; // every 10th line, print a blank line if(counter == 10) { Console.WriteLine(); counter = 0; // reset the line counter } } } } [/csharp]

Size of int, double, char and bool

image_pdfimage_print

   
 
/*
C# Programming Tips &amp; Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

//
//  Sizes.cs -- returns the sixes of C# data types.
//              Compile with the following command line:
//                  csc /unsafe sizes.cs
//
namespace nsSizes
{
    using System;
    struct TestStruct
    {
        int    x;
        double y;
        char   ch;
    }

    public class Sizes
    {
        static public unsafe void Main ()
        {
            Console.WriteLine ("The size of a bool is " + sizeof (bool));
            Console.WriteLine ("The size of a char is " + sizeof (char));
            Console.WriteLine ("The size of an int is " + sizeof (int));
            Console.WriteLine ("The size of a long is " + sizeof (long));
            Console.WriteLine ("The size of an double is " + sizeof (double));
            Console.WriteLine ("The size TestStruct is " + sizeof (TestStruct));
        }
    }
}