![](/img/trans.png)
[英]How to resolve “The name *** does not exist in the current context” error?
[英]How to resolve this error: await and cursor does not exist in current context
private void button10_Click(object sender, EventArgs e)
{
var db = mongo.GetDatabase("milk123");
mongo.Connect();
var collection = db.GetCollection<BsonDocument>("stock123");
using (var cursor = await col.Find(new BsonDocument()).ToCursorAsync())
{
while (await cursor.MoveNextAsync())
{
foreach (var doc in cursor.Current)
{
Console.WriteLine(doc);
}
}
}
}
在执行它时,我收到以下错误:
等待并且光标在当前上下文中不存在。
await
关键字只能在async
方法中使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.