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

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

C#9个月前 (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://pythonopen.com/?id=1619

相关文章

C# 文件属性与转换为字节

获取文件属性    FileInfo fileInfo&nb...

C# System.IO.Path

System.IO.Path.GetExtension返回指定的路径字符串的扩展名。string&n...

C# MemoryStream转为Image

        //...

C# Graphics文本抗锯齿

g.TextRenderingHint = TextRenderingHint....

C# i++和++i的区别

核心区别操作顺序            ...

C# 比较两个Image对象是否相同

方法思路基础检查:先检查空引用和图像尺寸像素格式验证:确保两个图像的像素格式相同内存锁定:使用Loc...