usingSystem;usingExtensionMethods;namespaceEqual{classProgram{staticvoidMain(string[] args){double x =3.233;int exp =3;double y = x.Power(exp);
Console.WriteLine("{0}的{1}次方是{2}", x, exp, y);}}}namespaceExtensionMethods{publicstaticclassMyExtensions{//扩展方法:求实数的次方publicstaticdoublePower(thisdouble x,int exp){double result =1;for(int i =0; i < exp; i++){
result *= x;}return result;}}}