using System;
using System.Collections.Generic;using System.Linq;using System.Text;namespace OverridDemo2
{ class Program { static void Main(string[] args) { (new Program()).run(); } void run() { int arg1 = 10; float arg2 = 12.5f; int arg3 = 30; DoWorkWithData(); DoWorkWithData(arg1); DoWorkWithData(arg1, arg2);DoWorkWithData(intData:arg1, moreIntData:arg3);//指定传递给哪个参数.
DoWorkWithData(floatData:arg2,moreIntData:arg3); //指定传递给哪个参数. DoWorkWithData(arg1, arg2,arg3); } void DoWorkWithData(int intData=0, float floatData=0.0f, int moreIntData=0) { Console.WriteLine("intData:{0},floatData:{1},moreIntData:{2}", intData, floatData, moreIntData); }}
}注:在参数列表中,如果存在有默认值的和无默认值的情形,无默认值的参数必须在有默认值的参数前面.
eg: void DoWorkWithData(int intData, float floatData=0.0f, int moreIntData=0)
{ Console.WriteLine("intData:{0},floatData:{1},moreIntData:{2}", intData, floatData, moreIntData); }