当前位置:首页 > 开发 > 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://www.pythonopen.com/?id=1619

相关文章

CS0052 可访问性不一致: 字段类型“n1”的可访问性低于字段“n2”

问题CS0052 可访问性不一致: 字段类型“n1”的可访问性低于字段“n2”原因n1未使用publ...

C# CRC32算法

CRC32      class CRC32...

C# 时间操作

获取系统已运行时间    System.Environment.Tic...

C# string与StringBuilder速度测试

测试代码    Stopwatch time1 =...

C# 可空参数

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

C# System.IO.Path

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