通用列表不会出现
此示例使用 where
查找所有缺货的产品。
public void Linq2()
{
List<Product> products = GetProductList();
var soldOutProducts =
from p in products
where p.UnitsInStock == 0
select p;
Console.WriteLine("Sold out products:");
foreach (var product in soldOutProducts)
{
Console.WriteLine("{0} is sold out!", product.ProductName);
}
}
结果:
售完产品:
- 安东厨师的秋葵浓汤已售完!
- 爱丽丝羊肉卖完了!
- 图林格州腊肠已售完!
- 戈贡佐拉泰利诺 (Gorgonzola Telino) 已售罄!
- 珀斯馅饼卖完了!
上面的例子是我从MSDN Samples得到的,这是Simple2,问题当我输入 List
时,Products 未显示在 Intellisense 中。当我手动输入时,出现以下错误:
仅限赋值、调用、递增、递减和新建对象表达式 可以用作语句
我能做些什么来解决这个问题?
This sample uses where
to find all products that are out of stock.
public void Linq2()
{
List<Product> products = GetProductList();
var soldOutProducts =
from p in products
where p.UnitsInStock == 0
select p;
Console.WriteLine("Sold out products:");
foreach (var product in soldOutProducts)
{
Console.WriteLine("{0} is sold out!", product.ProductName);
}
}
Result:
Sold out products:
- Chef Anton's Gumbo Mix is sold out!
- Alice Mutton is sold out!
- Thüringer Rostbratwurst is sold out!
- Gorgonzola Telino is sold out!
- Perth Pasties is sold out!
The above example i got from MSDN Samples, this is Simple2, the problem is when I enter List<Products>
, Products is not showing in Intellisense. When I enter it manually, I get the following error:
Only assignment, call, increment, decrement and new object expression
can be used as a statement
What can I do to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,
您的问题是您复制了链接的源。但此源代码既不包含
Product
也不包含GetProductList()
的定义请查看示例 此处 - 它拥有您需要的一切:
Ok,
your problem is that you copied the linked source. But this source does not contain the definitions for neither
Product
norGetProductList()
Please take a look at the example here - it has everything you need:
那是因为你没有定义类。您添加类定义。您可以将类写入同一个文件中,添加一个新的类文件并将 Product 的定义放入其中。
That's because you don't have the class defined. You to add the class definition. You could write the class in the same file, add a new class file and put the definition of Product in it.