Function will give three result SUM, SUB, MUL at one call.
class MyProgram
{
public static void Main()
{
int a = 10, b = 20, c = 0, d = 0, e = 0;
Func(a, b, ref c, ref d, ref e);
Console.WriteLine("Sum= {0}", c);
Console.WriteLine("Sub= {0}", d);
Console.WriteLine("Mul= {0}", e);
Console.ReadLine();
}
public static void Func(int p, int q, ref int r, ref int s, ref int t)
{
r = p + q;
s = p - q;
t = p * q;
}
}
Get C#, ASP.NET, HTML, JavaScript, XML, WCF, Web services and Ajax tips.
menu
- Home
- Asp.Net
- MVC
-
C#
- Ref
- Constructor
- Constructor Program
- Jagged Array
- Command Line Argument
- Stack and Heap
- Ref and Out
- Const, ReadOnly and Static
- Generic
- Two Interfaces With Same Method Name
- Inheritance
- Is Keyword
- Custom List with OnAdd Event
- Data Annotation
- Covariance & Contravariance
- Signing - Strong vs Weak Reference
- Sorting List by IComparable vs IComparer
- WCF
- JavaScript
- SQL
- Others
- Contact
Sunday, August 1, 2010
Get more than one result from a function
Function will give three result SUM, SUB, MUL at one call.
class MyProgram
{
public static void Main()
{
int a = 10, b = 20, c = 0, d = 0, e = 0;
Func(a, b, ref c, ref d, ref e);
Console.WriteLine("Sum= {0}", c);
Console.WriteLine("Sub= {0}", d);
Console.WriteLine("Mul= {0}", e);
Console.ReadLine();
}
public static void Func(int p, int q, ref int r, ref int s, ref int t)
{
r = p + q;
s = p - q;
t = p * q;
}
}
class MyProgram
{
public static void Main()
{
int a = 10, b = 20, c = 0, d = 0, e = 0;
Func(a, b, ref c, ref d, ref e);
Console.WriteLine("Sum= {0}", c);
Console.WriteLine("Sub= {0}", d);
Console.WriteLine("Mul= {0}", e);
Console.ReadLine();
}
public static void Func(int p, int q, ref int r, ref int s, ref int t)
{
r = p + q;
s = p - q;
t = p * q;
}
}
Subscribe to:
Posts (Atom)