生成方法,如int MethodA(int a,params string[] b);
怎么声明定义/这个方法,params,msdn是有ref,out的例子,没有params的例子
// Declares a method.
CodeMemberMethod method1 = new CodeMemberMethod();
method1.set_Name("TestMethod");
// Declares a string parameter passed by reference.
CodeParameterDeclarationExpression param1 = new
CodeParameterDeclarationExpression("System.String", "stringParam");
param1.set_Direction(FieldDirection.Ref);
method1.get_Parameters().Add(param1);
// Declares a Int32 parameter passed by incoming field.
CodeParameterDeclarationExpression param2 = new
CodeParameterDeclarationExpression("System.Int32", "intParam");
param2.set_Direction(FieldDirection.Out);
method1.get_Parameters().Add(param2);
// A VJ# code generator produces the following source code for
// the preceeding example code:
// private void TestMethod(/** @ref */ String stringParam,
// /** @ref */ int intParam)
// {
// } //TestMethod
怎么声明定义/这个方法,params,msdn是有ref,out的例子,没有params的例子
// Declares a method.
CodeMemberMethod method1 = new CodeMemberMethod();
method1.set_Name("TestMethod");
// Declares a string parameter passed by reference.
CodeParameterDeclarationExpression param1 = new
CodeParameterDeclarationExpression("System.String", "stringParam");
param1.set_Direction(FieldDirection.Ref);
method1.get_Parameters().Add(param1);
// Declares a Int32 parameter passed by incoming field.
CodeParameterDeclarationExpression param2 = new
CodeParameterDeclarationExpression("System.Int32", "intParam");
param2.set_Direction(FieldDirection.Out);
method1.get_Parameters().Add(param2);
// A VJ# code generator produces the following source code for
// the preceeding example code:
// private void TestMethod(/** @ref */ String stringParam,
// /** @ref */ int intParam)
// {
// } //TestMethod
解决方案 »
- 现在大家都用什么样的测试工具?
- 清除宽带拨号登陆后自动保存的账号
- C#怎样打开Word,Excel和ppt软件
- WINFROM程序如何保存一些状态值,就像WEB里的 SESSION 我要保存登陆的用户,应该保存在哪里?
- 继承了List然后想override操作符[]
- 一个有关TextBox失去焦点问题(急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)
- VC 用C#做的系统,界面只显示一半,解答
- 大虾帮忙,!->如何用程序实现在Panel中加入一个控件?
- 数剧绑定?
- 如何获得左右键同时按下的事件!
- DataTable的合并问题
- System.Drawing.PrintDocument为什么要求保存一个xps文档?
本质上,params参数就是一个数组。http://msdn.microsoft.com/zh-cn/library/w5zay9db(v=vs.110).aspx你可以看到这样的调用方法:
int[] myIntArray = { 5, 6, 7, 8, 9 };
UseParams(myIntArray);
等价:
UseParams(5, 6, 7, 8, 9);