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;
}
}
Month: February 2011
Some Operator on int
using System;
public class MyMainClass10 {
static void Main(string[] args) {
int a,b,c,d,e,f;
a = 1;
b = a + 6;
c = b - 3;
d = c * 2;
e = d / 2;
f = e % 2;
}
}
displays a conversion table of Fahrenheit to Celsius
/*
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
/*
C# Programming Tips & 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
/*
C# Programming Tips & 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;
}
}
}
Assing value to int value
public class Values{
static void Main( ) {
int myInt = 7;
System.Console.WriteLine("Initialized, myInt: {0}", myInt);
myInt = 5;
System.Console.WriteLine("After assignment, myInt: {0}",myInt);
}
}
demonstrates variables
using System;
public class Example2DemonstratesVariables {
public static void Main() {
int x;
int y;
x = 10;
Console.WriteLine("x contains " + x);
y = x / 2;
Console.Write("y contains x / 2: ");
Console.WriteLine(y);
}
}

