C#什么是=>;句法意义
我试图理解C#,但对这段代码感到非常困惑C#什么是=>;句法意义,c#,C#,我试图理解C#,但对这段代码感到非常困惑 Thread thread = new Thread(new ThreadStart(() => { Thread.Sleep(_rnd.Next(50, 200)); //do other stuff })); thread.Start(); 我知道正在创建一个线程,然后启动它,但我不理解本例中的=>语法。通过查看该网站上的其他帖子,很难找到关于=>的帖子,我认为这与代表有关,或者有什么东西正在被返回?有人能解释一下
Thread thread = new Thread(new ThreadStart(() =>
{
Thread.Sleep(_rnd.Next(50, 200));
//do other stuff
}));
thread.Start();
我知道正在创建一个线程,然后启动它,但我不理解本例中的=>语法。通过查看该网站上的其他帖子,很难找到关于=>的帖子,我认为这与代表有关,或者有什么东西正在被返回?有人能解释一下吗?谢谢 下面,您将找到一些处理函数和委托的不同方法。所有人都做同样的事情:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SO39543690
{
class Program
{
static Random _rnd = new Random();
static void Proc()
{
Console.WriteLine("3. Processing...");
Thread.Sleep(_rnd.Next(50, 200));
}
static void Main(string[] args)
{
Thread thread = new Thread(new ThreadStart(() =>
{
Console.WriteLine("1. Processing...");
Thread.Sleep(_rnd.Next(50, 200));
}));
thread.Start();
thread = new Thread(() =>
{
Console.WriteLine("2. Processing...");
Thread.Sleep(_rnd.Next(50, 200));
});
thread.Start();
thread = new Thread(Proc);
thread.Start();
thread = new Thread(delegate ()
{
Console.WriteLine("4. Processing...");
Thread.Sleep(_rnd.Next(50, 200));
});
thread.Start();
Action proc = () =>
{
Console.WriteLine("5. Processing...");
Thread.Sleep(_rnd.Next(50, 200));
};
thread = new Thread(new ThreadStart(proc));
thread.Start();
Console.WriteLine("END");
Console.ReadLine();
}
}
}
这是一种
委托
速记语法