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));
        }
    }
}

           
         
     


Calculate: int and double

image_pdfimage_print

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

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

namespace nsArea
{
    using System;
    public class Area
    {
        static public void Main ()
        {
            double Area;
            int Radius = 42;
            GetArea (Radius, out Area);
            Console.WriteLine ("The area of a circle with radius {0} is {1}",
                                Radius, Area);
        }
        static void GetArea (int radius, out double area)
        {
            const double pi = 3.14159;
            area = pi * radius * radius;
        }
    }
}