基本算法
class Program { static void Main() { #region //HashSet<int> myList = new HashSet<int>(); //while (myList.Count < 100) //{ // int num = new Random().Next(1, 101); // myList.Add(num); //} //foreach (int item in myList) //{ // Console.WriteLine(item); //} //Console.WriteLine(myList.Count); //Console.ReadLine(); #endregion #region 随机数插入 //HashSet<int> vs = new HashSet<int>(); //while (vs.Count < 100) //{ // vs.Add(new Random().Next(1, 101)); //} //foreach (var item in vs) //{ // Console.WriteLine(item); //} //Console.WriteLine(vs.Count); //Console.ReadLine(); #endregion #region 1-2+3-4 //int sum = 0; //for (int i = 1; i <= 11; i++) //{ // if (i % 2 == 0) // { // sum -= i; // } // else // { // sum += i; // } //} //Console.WriteLine(sum); //Console.ReadLine(); #endregion #region 1,1,2,3,5,8,13...递归 //Console.WriteLine(Jaia(20)); //Console.ReadLine(); #endregion #region //new B(); //Console.WriteLine(); #endregion #region 冒泡 //MaoPao(); #endregion #region 反射程序集 //Assembly asm = Assembly.LoadFrom(@"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll"); //var a= asm.GetTypes(); //foreach (var item in a) //{ // Console.WriteLine(item); //} #endregion #region 反射基本信息 //int a = 0; //TypeExplore(a.GetType()); #endregion #region 反射基本类型 //int b = 2; //Type type = b.GetType(); //MemberExplore(b.GetType()); #endregion #region 无参数构造函数创建参数 //使用CreateInstance创建对象 Assembly asm = Assembly.GetExecutingAssembly(); object obj = asm.CreateInstance("ConsoleApp12.Calculator", true); //使用Activator.CreateInstance ObjectHandle handler = Activator.CreateInstance(null, "ConsoleApp12.Calculator"); Object objj = handler.Unwrap(); #endregion } private static int Jaia(int a) { if (a <= 0) return 0; else if (a == 1 || a == 2) return 1; else { return Jaia(a - 1) + Jaia(a - 2); } } /// <summary> /// 冒泡 /// </summary> public static void MaoPao() { int[] array = { 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 }; int temp = 0; 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[i]; array[i] = array[j]; array[j] = temp; } } } } /// <summary> /// 反射基本信息 /// </summary> /// <param name="t"></param> public static void TypeExplore(Type t) { StringBuilder sb = new StringBuilder(); sb.Append("名称信息:\n"); sb.Append("Name:" + t.Name + "\n"); sb.Append("基类型:" + t.BaseType + "\n"); Console.WriteLine(sb); } public static void MemberExplore(Type t) { StringBuilder sb = new StringBuilder(); MemberInfo[] memberInfos = t.GetMembers(); sb.Append("查看类型" + t.Name + "的成员信息;\n"); foreach (MemberInfo mi in memberInfos) { sb.Append("成员" + mi.ToString().PadRight(40) + "类型:" + mi.MemberType + "\n"); } Console.WriteLine(sb.ToString()); } }