标签:
引用的时候需要在参数和使用的时候加上 ref 关键字
static bool addnum (ref int val) //引用
{
++val;
return true;
}
参数数组的概念,可以接受该类型的数组,不限制大小,关键字 params
static int getlength (params int[] vals) //参数数组
{
int sum = 0;
foreach (int val in vals)
{
sum += val;
}
return sum;
}
输出参数的概念,类似参数数组,不过声明的时候可以不初始化
static int MaxValue (int[] intArray, out int maxIndex) //输出参数
{
int maxValue = intArray[0];
maxIndex = 0;
for (int i = 1; i < intArray.Length; ++i)
{
if (intArray[i] > maxValue)
{
maxValue = intArray[i];
maxIndex = i;
}
}
return maxValue;
}
delegate double ProcessDelegate (double param1, double param2);
static double Multiply (double param1, double param2)
{
return param1 * param2;
}
static double Divide (double param1, double param2)
{
return param1 / param2;
}
static void Main(string[] args)
{
ProcessDelegate process;
string input = Console.ReadLine();
if (input.CompareTo("M") == 0)
{
process = new ProcessDelegate (Multiply);
}
else
{
process = new ProcessDelegate(Divide);
}
double param1 = 3.123;
double param2 = 23.12;
Console.WriteLine("{0}", process(param1, param2));
}
abstract class MyClass1
{
}
sealed class MyClass2
{
}
标签:
原文地址:http://www.cnblogs.com/wushuaiyi/p/4632531.html