c# Data Types Examples


using System;

namespace DataTypes

{

/// <summary>

/// Summary description for TestClass.

/// </summary>

class TestClass

{

const double PI = 3.1415;

public static void Sume(int a, int b)

{

Console.WriteLine(“The sume of elements {0} and {1} is {2}”,a,b,a+b);

}

public static void SumeRef(ref int a,ref int b)

{

a = 4;

b = 6;

Console.WriteLine(“The sume of elements {0} and {1} is {2}”,a,b,a + b);

}

public static int SumeOut(int a, int b, out int sume)

{

sume = a+b;

Console.WriteLine(“The sume of elements {0} and {1} is {2}”,a,b,a+b);

return sume;

}

public class IntClass

{

public int I = 1;

}

struct Point3D

{

public float m_x;

public float m_y;

public float m_z;

public float [] GetArray()

{

float [] arr = new float[3];

arr[0] = m_x;

arr[1] = m_y;

arr[2] = m_z;

return arr;

}

}

public enum Days

{

Monday,

Tuesday,

Wensday,

Thursday,

Friday,

Saturday,

Sunday

}

interface IRect

{

int Width

{

get;

set;

}

int Height

{

get;

set;

}

int CalculateArea();

}

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main(string[] args)

{

string s = “declaration and init”;

Sume(3,2);

int a = 2;

int b = 3;

SumeRef(ref a,ref b);

int sume ;

sume = SumeOut(2,2, out sume);

// test class

int i = 10;

int j = i;

j = 11;

IntClass ic1 = new IntClass();

IntClass ic2 = ic1;

ic2.I = 100;

Console.WriteLine(“value of i is {0} and j is {1}”,i,j);

Console.WriteLine();

Console.WriteLine(“value of ic1.I is {0} and ic2.I is {1}”,ic1.I,ic2.I);

Console.WriteLine();

// boxing

char ch = ‘b’;

object obj = ch;

Console.WriteLine(“Char value is {0}”,ch);

Console.WriteLine(“Object value is {0}”,obj);

Console.WriteLine();

// unboxing

float q = 4.6f;

object ob = q;

Console.WriteLine(“Object value is {0}”,ob);

float r = (float)ob;

Console.WriteLine(“Float value is {0}”,r);

}

}

}

Advertisements

Thanks a lot for visiting this site .. Please leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s