根据我的理解async,await要做的主要事情之一就是使代码易于编写和阅读-但是使用它们是否等同于产生后台线程来执行长时间逻辑? 我目前正在尝试最基本的示例。我在行中添加了一些评论。你能为我澄清一下吗? // I don't understand why this method must be marked as `async`. private async void button1_Click(object sender, EventArgs e) { Task<int> access = DoSomethingAsync(); // task independent stuff here // this line is reached after the 5 seconds sleep from // DoSomethingAsync() method. Shouldn't it be reached immediately? …
假设我们有一个类似的类: class Person { internal int PersonID; internal string car; } 现在,我有一个此类的清单: List<Person> persons; 现在,此列表可以包含多个具有相同PersonID的实例,例如: persons[0] = new Person { PersonID = 1, car = "Ferrari" }; persons[1] = new Person { PersonID = 1, car = "BMW" }; persons[2] = new Person { PersonID = 2, car = "Audi" …