标签:code main image 泛型 void oid bsp img rgs
static void Main(string[] args) { //案例:把分拣奇偶数的程序用泛型实现。List<int> int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; List<int> left = new List<int>(); //偶数放左边 List<int> right = new List<int>(); //奇数放右边 for (int i = 0; i < nums.Length; i++) { if (nums[i] % 2 == 0) { left.Add(nums[i]); } else { right.Add(nums[i]); } } //输出 Console.Write("偶数是:"); foreach (var item in left) { Console.Write(item + ","); } Console.Write("/"); Console.Write("奇数是:"); foreach (var item in right) { Console.Write(item + ","); } Console.ReadKey(); }
标签:code main image 泛型 void oid bsp img rgs
原文地址:http://www.cnblogs.com/pyGIS/p/7210566.html