Classes & Method in ASP.NET .
protected void Page_Load(object sender, EventArgs e)
{
//Create object of class
CommonClass objCommonClass = new CommonClass();
//Call sum function by passing 2 parameters
int intSum1 = objCommonClass.Sum(10, 20);
Response.Write("Sum1 = "+intSum1);
//Call sum function by passing 3 parameters
int intSum2 = objCommonClass.Sum(10, 20,30);
Response.Write("<br/>");
Response.Write("Sum2 = " + intSum2);
}
public class CommonClass
{
//public is access modifier
//int return type
//Sum is name of function
//x,y are the parameters
public int Sum(int x, int y)
{
return x + y;
}
public int Sum(int x, int y, int z)
{
return x + y + z;
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.