当前位置:首页 > 开发 > C# > 正文内容

C# 缩减代码量的一些方式

C#7个月前 (12-20)
static void Main()
{
	Thread thread1 = new Thread(PrintNumbers);
	thread1.Start();
}
static void PrintNumbers()
{
	Console.WriteLine(1);
	Console.WriteLine(2);
}

>

    static void Main()
    {
        Thread thread1 = new Thread(() =>
        {
            Console.WriteLine(1);
            Console.WriteLine(2);
        });
        thread1.Start();
    }

        private void newTimer()
        {
            Timer timer = new Timer();
            timer.Interval = 1000;
            timer.Tick += tick;
            timer.Start();
        }
        private static void tick(object sender,EventArgs e)
        {
            Console.WriteLine(1);
            Console.WriteLine(2);
        }

>

        private void newTimer()
        {
            Timer timer = new Timer() { Interval = 1000 };
            timer.Tick += (sender1, e1) =>
            {
                Console.WriteLine(1);
                Console.WriteLine(2);
            };
            timer.Start();
        }



if (cBackgroundWorker != null)
    cBackgroundWorker.CancelAsync();

>

cBackgroundWorker?.CancelAsync();

        public string GetText
        {
            get
            {
                return "0000";
            }
        }

>

        public string GetText
        {
            get => "0000";
        }

>

        public string GetText => "0000";


转载请注明出处。

本文链接:http://www.pythonopen.com/?id=1619

相关文章

C# string与StringBuilder速度测试

测试代码    Stopwatch time1 =...

C# 获取MD5

命名空间     using System.Securi...

C# [OnPaint]和[OnPaintBackground]的区别

OnPaint和OnPaintBackground的主要功能区别OnPaint:OnPaint方法主...

C# decimal

概述在 C# 中,decimal是一种数据类型,用于表示高精度的十进制数值。它主要用于需要精确计算的...

C# ref 和out

ref关键字概念:ref是 C# 中的一个关键字,用于按引用传递参数。当在方法调用中使用ref关键字...