标签:style blog http io ar color sp for on
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace nange_1 { class A { public void listint(params int[] array) { for (int i = 0; i < array.Length; i++) { array[i] = array[i] * 10;
Console.WriteLine("{0}", array[i]);
} } } class Program { static void Main(string[] args) { int a = 1, b = 2, c = 3; A objA = new A(); objA.listint(a, b, c); Console.WriteLine(a + " " + b + " " + c); Console.ReadLine(); } } }
从输出结果上看实参的值没有受形参的影响!
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace nange_1 { class A { public void listint(params int[] array) { for (int i = 0; i < array.Length; i++) { array[i] = array[i] * 10; Console.WriteLine("{0}",array[i]); } } } class Program { static void Main(string[] args) { int []array=new int[]{1,2,3}; A objA = new A(); objA.listint(array); foreach(int x in array) Console.WriteLine("{0}",x);//输出每个元素 Console.ReadLine(); } } }
//通过实参的值改变了形参的值
标签:style blog http io ar color sp for on
原文地址:http://www.cnblogs.com/leijiangtao/p/4129226.html