数组在方法中的传递:
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
namespace 数组在方法中的传递
{
class Program
{
static void Main(string[] args)
{
At ced = new At();
int[] arr2 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
//把arr2中的数组传递到arr里去
ced.Arr(arr2);
for (int i = 0; i < ced.arr.Length; i++)
{
Console.Write("{0}\t",ced.arr[i]);
}
}
}
class At
{
public int[] arr = new int[9];
public int[]Arr(int[] arr1)
{
arr=arr1;
return arr;
}
}
}
数组也能在属性中进行传递:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 数组在属性中的传递
{
class Program
{
static void Main(string[] args)
{
At ced = new At();
int[] arr2 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
//把arr2中的数组传递到arr里去
//ced.Arr(arr2);
ced.Arr = arr2;
for (int i = 0; i < ced.Arr.Length ; i++)
{
Console.Write("{0}\t",ced.Arr[i]);
}
}
}
class At
{
private int[] arr=new int[9];
public int[]Arr
{
get {return arr ;}//只读
set {arr=value; }//只写
}
}
}