How to use call delegates from class file to aspx.cs file
Dear FriendsI have write delegates in class file and also have more than 10 method. now i want to use that 10 method in aspx.cs page using delegates object. how its possible..
public delegate double Delegate_Multi(int a,int b);
class Class1
{
static double MultiplayvaluesFN(int val1,int val2)
{
return val1*val2;
}
static void Main(string[] args)
{
//Creating the Delegate Instance
Delegate_Multi delObj = new Delegate_Multi(MultiplayvaluesFN);
Console.Write("Please Enter Values");
int v1 = Int32.Parse(Console.ReadLine());
int v2 = Int32.Parse(Console.ReadLine());
//use a delegate for processing
double res = delObj(v1,v2);
Console.WriteLine ("Result :"+res);
Console.ReadLine();
}
}
public delegate int Delegatmethod(int a,int b);
public class Sampleclass
{
public int Add(int x, int y)
{
return x + y;
}
public int Sub(int x, int y)
{
return x + y;
}
}
protected void Page_Load(object sender, EventArgs e)
{
SampleMethod sc = new SampleMethod();
DelegatMethod delgate1 = sc.Add;
int i = delgate1(10, 20);
Console.WriteLine(i);
DelegatMethod delgate2 = sc.Sub;
int j = delgate2(20, 10);
DelegatMethod delgate3 = sc.Multiply;
int z = delgate3(20, 10);
}
public delegate int DelegatMethod(int a, int b);
public class SampleMethod
{
public int Add(int x, int y)
{
return x + y;
}
public int Sub(int x, int y)
{
return x - y;
}
public int Multiply(int x, int y)
{
return x - y;
}
}