Friday, October 26, 2007

Get-Set property in C#

using System;
using System.Collections.Generic;
using System.Text;

namespace Get_Set_Test
{
class Program
{

static void Main(string[] args)
{
//CREATE OBJECT
GetSet_Test obj = new GetSet_Test();

//SET VALUE OF THAT CLASS
obj.Val = 5;
//GET VALUE OF THAT CLASS
Console.WriteLine(obj.Val);
Console.ReadLine();



}
public void TypeTest(Control
obj)
{

}
}

class GetSet_Test
{
int val;
///
/// Set or Get value of variable
///

public int Val
{
//SET VALUE TO VARIABLE
set
{
val = value; ;
}
//GET VALUE OF THAT VARIABLE
get
{
return val;
}
}
}
}

Tuesday, October 16, 2007

User Event in C#

Very simple user event in C#. Codes are:

using System;
using System.Collections.Generic;
using System.Text;

namespace Events
{
class Program
{
static void Main(string[] args)
{
EventTestClass obj = new EventTestClass();
obj.RaiseEvent1 += new EventTestClass.TestEventDelegate(obj_RaiseEvent);
obj.Run("call 1", "arg");
obj.Run("call 2", "arg");
obj.Run("call 3", "arg");
Console.ReadLine();

}

static void obj_RaiseEvent(object sender, object Args)
{
Console.WriteLine("Done. "+sender.ToString()+"...............\n");
}

}
class EventTestClass
{
public delegate void TestEventDelegate(object sender, object Args);
public event TestEventDelegate RaiseEvent1;
public EventTestClass()
{

}

public void Run(object sender, object Args)
{
Console.WriteLine("Run called");
RaiseEvent1(sender, Args);
}

}

}