.
, . :
_ _
: ref, out, params.
(, , object, , ..).
, . . .. .
:
1. ;
2. (ref);
3. (out);
4. - (params).
:
1) , ;
2) ;
3) , .
1.
static double square(double a, double b, double c)
{
double s, p=(a+b+c)/2;
return s = Math.Sqrt(p * (p - a) * (p - b) * (p - c));//
}
2.
class Program
{
public static void Change(int a, int b)
{
int r = a;
a = b;
b = r;
}
static void Main(string[] args)
{
int x = 10, y = 5;
Console.WriteLine("x=" + x + " y=" + y);
Change(x,y);
Console.WriteLine("x=" +x + " y=" + y);
}
, , . , , .
, ref, .. .
class Program
{
public static void Change(ref int a, ref int b)
{
int r = a;
a = b;
b = r;
}
static void Main(string[] args)
{
int x = new int(), y = new int();
x = 5; y = 10;
Console.WriteLine("x=" + x + " y=" + y);
Change(ref x, ref y);
Console.WriteLine("x=" + x + " y=" + y);
}
, , , .
out , . , , ( ). , , , .
|
|
static void fun(double x, out int integer, out double fraction)
{
integer=(int)x;
fraction=x-integer;
}
static void Main(string[] args)
{
double number = 1.23456;
int iPart;
double dPart;
//integer fraction
fun(number,out iPart,out dPart);
Console.WriteLine(" {0}, {1}",iPart,dPart);
}
( ref out) . return.
.
, .. .
, .. . , .