zoukankan      html  css  js  c++  java
  • 基本算法

        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:WindowsMicrosoft.NETFrameworkv2.0.50727System.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("名称信息:
    ");
                sb.Append("Name:" + t.Name + "
    ");
                sb.Append("基类型:" + t.BaseType + "
    ");
                Console.WriteLine(sb);
            }
    
            public static void MemberExplore(Type t)
            {
                StringBuilder sb = new StringBuilder();
                MemberInfo[] memberInfos = t.GetMembers();
                sb.Append("查看类型" + t.Name + "的成员信息;
    ");
                foreach (MemberInfo  mi in memberInfos)
                {
                    sb.Append("成员" + mi.ToString().PadRight(40) + "类型:" + mi.MemberType + "
    ");
                }
                Console.WriteLine(sb.ToString());
            }
        }
  • 相关阅读:
    boost::asio在VS2008下的编译错误
    Java集合框架——接口
    ACM POJ 3981 字符串替换(简单题)
    ACM HDU 1042 N!(高精度计算阶乘)
    OneTwoThree (Uva)
    ACM POJ 3979 分数加减法(水题)
    ACM HDU 4004 The Frog's Games(2011ACM大连赛区第四题)
    Hexadecimal View (2011ACM亚洲大连赛区现场赛D题)
    ACM HDU 4002 Find the maximum(2011年大连赛区网络赛第二题)
    ACM HDU 4001 To Miss Our Children Time (2011ACM大连赛区网络赛)
  • 原文地址:https://www.cnblogs.com/HuangLiming/p/14028279.html
Copyright © 2011-2022 走看看