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

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

C#5个月前 (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# 中实现类似于 Windows 资源管理器的“名称”排序方式

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

C# BackgroundWorker

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

C# BackgroundWorker的例子

以下是一个使用 BackgroundWorker 组件在 C# 中实现后台执行任务,同时在主线程更新...

C# decimal

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

c# Invalidate、Refresh、Refreshitem、Refreshitems的功能

Invalidate方法功能概述Invalidate方法主要用于使控件的特定区域(整个控件或部分区域...