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

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

C#6个月前 (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# 可空参数

using System; using System.Runtime.Inte...

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

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

C# decimal

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

C# 类接口

定义接口是一种抽象类型,它定义了一组方法签名(方法名称、参数列表和返回类型),但没有方法体。接口用于...

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

核心区别操作顺序            ...

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

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