C# 缩减代码量的一些方式
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";
转载请注明出处。