- 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
for (int i = 0; i 10; i++) { if ((i == 0) || (i == 9)) { System.Console.WriteLine(* * * * * * * * * * * *); } else { System.Console.WriteLine(* *); } } int[] ? myArray ? = ? new ? int[5]{1,2,3,4,5}; for(int ? i=0;i myArray.Length;i++) { ? ? ? ? ? Console.Writeline(myArray[i]); } ? 或者: foreach(int ? num ? in ? myArray) { Console.Writeline(num); } 传递值类型参数 值类型变量直接包含其数据,这与引用类型变量不同,后者包含对其数据的引用。因此,向方法传递值类型变量意味着向方法传递变量的一个副本。方法内发生的对参数的更改对该变量中存储的原始数据无任何影响。如果希望所调用的方法更改参数值,必须使用 ref 或 out 关键字通过引用传递该参数。 示例 1:通过值传递值类型 class PassingValByVal{ static void SquareIt(int x) // The parameter x is passed by value. // Changes to x will not affect the original value of myInt. { x *= x; Console.WriteLine(The value inside the method: , x); } public static void Main() { int myInt = 5; Console.WriteLine(The value before calling the method: , myInt); SquareIt(myInt); // Passing myInt by value. Console.WriteLine(The value after calling the method: , myInt); }} 输出 The value before calling the method: 5The value inside the method: 25The value after calling the method: 5 代码讨论 变量 myInt 为值类型,包含其数据(值 5)。当调用 SquareIt 时,myInt 的内容被复制到参数 x 中,在方法内将该参数求平方。但在 Main 中,myInt 的值在调用 SquareIt 方法之前和之后是相同的。实际上,方法内发生的更改只影响局部变量 x。 示例 2:通过引用传递值类型 class PassingValByRef{ static void SquareIt(ref int x) // The parameter x is passed by reference. // Changes to x will affect the original value of myInt. { x *= x; Console.WriteLine(The value inside the method: , x); } public static void Main() { int myInt = 5; Console.WriteLine(The value before calling the method: , myInt); SquareIt(ref myInt); // Passing myInt by reference. Co
文档评论(0)