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

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

C#4个月前 (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# 前++,与后++的区别

简单一句话,前++是自身先加1,再运算,后加加是先运算,然后再自身加1后++   ...

C# 将函数作为参数传递

无参数    static void Main(s...

在 C# 中实现类似于 Windows 资源管理器的“名称”排序方式

要在 C# 中实现类似于 Windows 资源管理器的“名称”排序方式,你需要考虑以下几点:1. 不...

C# BackgroundWorker

1.概述BackgroundWorker是一个在 WinForms 应用程序中用于简化在后台线程执行...

C# System.IO.Path

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

C# Browsable(bool)

在编程中(比如常见的 C# 语言在开发 Windows Forms 等应用程序时),Browsabl...