static int sumAdd(paras int[] datas)
{
int sum = 0;
foreach(int x in datas)
sum += x;
return sum;
}
static void main()
{
sunAdd(1,2,3,4,5);
}
static void Main(string[] args)
{
Console.WriteLine("I love C&&");
int val = 10;
Console.WriteLine("val‘s value is:{0}",val);
changeValue(ref val);
Console.WriteLine("val‘s value is:{0}",val);
}
static int changeValue(ref int val)
{
return val *= 2;
}void changeValue(int &val)
{
val *= 2;
}
void main()
{
int val = 10;
cout<<"val‘s value is:"<<val<<endl;
changeValue(val);
cout<<"val‘s value is:"<<val<<endl;
}static void outChange(int x, out int y)
{
y = 2 * x;
}
static void Main(string[] args)
{
int x = 100;
int y;
outChange(x,out y);
Console.WriteLine("out y‘s value is:{0}",y);
}
namespace ConsoleApplication1
{
class Program
{
public delegate void delFunc(string str); // 委托的声明
public static void testDelOne(string str) //定义委托对应的函数1
{
Console.WriteLine("This is delegate one:" + str);
}
public static void testDelTwo(string str) //定义委托对应的函数2
{
Console.WriteLine("This is delegate two:" + str);
}
public static void testDelThree(string str) //定义委托对应的函数3
{
Console.WriteLine("This is delegate three:" + str);
}
static void Main(string[] args)
{
Console.WriteLine("**************Test delegate use like C function pointer***************");
delFunc fp = testDelOne;
fp(" in 1.1");
delFunc xxpp = new delFunc(testDelThree);
xxpp("in 1.3");
Console.WriteLine("****************************Test delegate +=**************************");
fp += testDelTwo;
fp(" in 2");
Console.WriteLine("****************************Test delegate + **************************");
delFunc fpp = testDelThree;
//delFunc fpAll = fp + fpp;
delFunc fpAll = fp + testDelThree;
fpAll(" in 3");
Console.WriteLine("****************************Test delegate -=*************************");
fpp -= testDelTwo;
fpp("in fpp 2");
fpAll -= testDelTwo;
fpAll("in fpAll2");
Console.WriteLine("****************************Test delegate -**************************");
fpAll = fpAll - testDelOne;
fpAll(" in last");
}
}
}
delegate void del(string str);
void funcName(string str){//....}原文:http://blog.csdn.net/ddupd/article/details/21642739