标签:
#region 递归 private static int sum(int num) { if (num == 0) { return 1; } else { return num+sum(num - 1); } } #endregion
#region 冒泡排序 private static void Maopao() { int[] array =new int[] { 20,5,4,5,8 }; int temp; for (int i = 0; i <array.Length-1; i++) { for (int j = i+1; j < array.Length; j++) { if (array[j]<array[i]) { temp = array[j]; array[j] = array[i]; array[i] = temp; } } } for (int i = 0; i < array.Length; i++) { Console.WriteLine(array[i]); } Console.ReadKey(); } #endregion
#region 去除重复 private static void Dis() { int [] array ={10,20,10,3,2,2,5}; List<int> list = new List<int>(); for (int i = 0; i < array.Length-1; i++) { Console.WriteLine("list.IndexOf(array[i]):{0}", list.IndexOf(array[i])); if (list.IndexOf(array[i])==-1) { list.Add(array[i]); } } String[] s = { "a", "b", "b", "c" }; String[] q = s.Distinct().ToArray(); for (int i = 0; i < q.Length-1; i++) { Console.WriteLine("q:{0}", q[i]); } foreach (var item in list) { Console.WriteLine("list:{0}", item); } List<int> list1 = new List<int>(); list1.Add(10); list1.Add(11); list1.Add(12); list1.Add(10); var disList = list1.Distinct(); foreach (var item in disList) { Console.WriteLine("list1:{0}", item); } Console.ReadKey(); } #endregion
#region 字符串反转 private static void Fanzhuan() { string str = "我是好人"; // List<string> list = new List<string>(); for (int i = str.Length-1; i >=0; i--) { Console.WriteLine(str.Substring(i,1)); } Console.ReadKey(); } #endregion
标签:
原文地址:http://www.cnblogs.com/sl372/p/5576151.html