- string str = "1 2 3 4 5 6 7 8 9";
- string[] strNew = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- ArrayList oddList = new ArrayList();//存放奇数的集合
- ArrayList evenList = new ArrayList();//存放偶数的集合
- for (int i = 0; i < strNew.Length; i++)
- {
- if (Convert.ToInt32(strNew[i]) % 2 != 0)
- {
- oddList.Add(strNew[i]);
- }
- else
- {
- evenList.Add(strNew[i]);
- }
- }
- oddList.AddRange(evenList);
- for (int i = 0; i < oddList.Count; i++)
- {
- Console.Write(oddList[i]);
- }
- Console.ReadKey();
复制代码 |