我看到了一些以前回答的关于在C#中向IEnumerable添加项目的问题,但是我在尝试在VB.NET中实现建议的解决方案时遇到困难。如何在VB.NET中添加项目到IEnumerable(Of T)?
Option Strict On
Dim customers as IEnumerable(Of Customer)
' Return customers from a LINQ query (not shown)
customers = customers.Concat(New Customer with {.Name = "John Smith"})
上面的代码提供了错误:然后
Option Strict On disallows implicit conversions from Customer to IEnumerable(Of Customer)
VS2008建议使用CTYPE,但导致运行时坠毁我。我错过了什么?
很好的答案。我也怀疑item.Concat,特别是Prepend做同样的事情。如果我是你,我会删除它;-) – 2009-09-11 12:59:33
我想我们会的,是的。 – 2009-09-11 13:28:36