Escolar Documentos
Profissional Documentos
Cultura Documentos
Objectives
Problem Statement:
Write a program to calculate the area of a rectangle and a
square.
{
Calculator cal = new Calculator();
// The following statement is calling the
// AddNumber method and passing 10 and
// 20 as the parameter list.
int value=cal.AddNumber(10, 20);
Console.WriteLine("The result is
{0}", value);
Console.ReadLine();
}
}
Output: The output parameters are used to pass the value out
of the method. The following example shows the parameters
passed by reference:
void CalculateSum( ref int num1,ref int num2, out
int result)
{
result=num1+num2;
}
void Accept()
{
int val1=10;
int val2=2;
int recieveVal;
CalculateSum( ref val1,ref val2,out
recieveVal);
}
Problem Statement:
Write a program to swap two numbers by using reference type
parameters in a method.