首页 > 代码库 > 同步为两个数组赋值

同步为两个数组赋值

          使用可变参数同步两个数组中的数据,一个存放类型,另外一个存放数据,两个数组一一对应。

 1 class Program 2     { 3         public static void InitArray(out string[] xType,out string[] xData, params string[] paraList) 4         { 5             Debug.Assert(paraList.Length % 2 == 0);   6             int arrayLength = paraList.Length / 2; 7             string[] typeArray = new string[arrayLength]; 8             string[] dataArray = new string[arrayLength]; 9             for (int i = 0; i < arrayLength; i++)10             {11                 typeArray[i] = paraList[i * 2];12                 dataArray[i] = paraList[i * 2 + 1];13             }14             xType = typeArray;15             xData =http://www.mamicode.com/ dataArray;16         }17         static void Main(string[] args)18         {19             string[] typeArray;20             string[] dataArray;21             InitArray(out typeArray, out dataArray,"1001", "EX01", "1000", "道路","1011","Point" );22             for (int i = 0; i < typeArray.Length; i++)23             {24                 Console.WriteLine("类型:" + typeArray[i] + ",数据:" + dataArray[i]);25             }26             Console.ReadKey(); 27         }28     }

    

同步为两个数组赋值