c#

//单例

    //单例
    public class SingleClass
    {
        // 1私有化构造函数
        private  SingleClass(){}
        // 2私有属性
        private  static SingleClass instance = new SingleClass();
        // 3
        public static  SingleClass GetInstance()   { return instance; }
        public void Say() 
        {
            Console.WriteLine("33");
        }
    }

//冒泡

  int[] array = new int[] { 32, 43, 63, 2, 1, 4 };
            // 一共循环 length -1
            for (int i = 0; i < array.Length-1; i++)
            {
                // 内存循环 j - i - 1 次 第二条件判断 是,继续循环,自己老写错
                for (int j = array.Length - 1; j > i; j--)
                {
                    if (array[j]>array[j-1])
                    {
                        int temp = array[j];
                        array[j ] = array[j - 1];
                        array[j - 1] = temp;
                    }
                }
            }
            Console.WriteLine(string.Join(" ",array));
            array.ToList().ForEach (x => Console.WriteLine(x)); 

 //异步

        private async void 获取数据_ClickAsync(object sender, EventArgs e)
        {
            HttpClient httpClient = new HttpClient();
            var ss = await httpClient.GetStringAsync("https://www.baidu.com");
            this.richTextBox1.Text = ss;
        }

 //委托

           //传递方法作为变量
      void GoHome(H h) { Console.WriteLine("回家"); Console.WriteLine("找妈妈"); h(); Console.WriteLine("睡觉"); } GoHome(sayHi); Console.ReadKey(); void sayHi() { Console.WriteLine("Hi"); }

 

posted @ 2021-09-17 21:55  vba是最好的语言  阅读(78)  评论(0编辑  收藏  举报