.net 对IList的Linq查询<;T>;字符串成员
我有下面的模型,我正在将其加载到IList集合中并对其运行Linq查询。我遇到的问题是Linq查询将OPCServer成员作为IEnumerable(of Char)返回。这是否有不返回基础字符串的原因 如果我对每个使用.net 对IList的Linq查询<;T>;字符串成员,.net,vb.net,string,linq,.net,Vb.net,String,Linq,我有下面的模型,我正在将其加载到IList集合中并对其运行Linq查询。我遇到的问题是Linq查询将OPCServer成员作为IEnumerable(of Char)返回。这是否有不返回基础字符串的原因 如果我对每个使用对集合进行迭代,那么它将按预期返回字符串 我是否必须手动将其转换回“工作代码”部分中显示的格式 型号 Friend Class OpcDataTags Public Property Host As String Public Property HostLive
对集合进行迭代,那么它将按预期返回字符串
我是否必须手动将其转换回“工作代码”部分中显示的格式
型号
Friend Class OpcDataTags
Public Property Host As String
Public Property HostLive As Boolean
Public Property OpcServer As String
Public Property OpcChannel As String
Public Property PlcDns As String
Public Property PlcIP As String
Public Property Zone As String
Public Property DataBlock As String
Public Property StartByte As Int16
Public Property ByteSize As Int16
Public Property DataType As String
Public Property Subscribed As Boolean
Public Property Description As String
Public Property ArraySize As Nullable(Of Int32)
Public Property Abbreviation As String
Public Property PlcID As Int32
End Class
收藏
Friend Property OpcTags As IList(Of OpcDataTags)
LinqQuery
Dim server = From o In OpcTags.First.OpcServer
工作代码
Dim result = From o In OpcTags.First.OpcServer
Dim server As String = New String(result.ToArray)
你真正想要实现的是:
' From LINQ's point of view, OpcTags is an IEnumerable< OpcDataTags >
Dim serverQuery = From o In OpcTags Select o.OpcServer
' And now you've narrowed it down to an IEnumerable< String >
Dim firstOne = serverQuery.First
' And now you're selecting the first String from that enumeration of strings
String类实现了IEnumerable
,您实际上是在强迫它
看起来像是更多值的来源(因此隐式地将其转换为最佳的IEnumerable
匹配,即IEnumerable
)您实际想要实现的是:
' From LINQ's point of view, OpcTags is an IEnumerable< OpcDataTags >
Dim serverQuery = From o In OpcTags Select o.OpcServer
' And now you've narrowed it down to an IEnumerable< String >
Dim firstOne = serverQuery.First
' And now you're selecting the first String from that enumeration of strings
String类实现了IEnumerable
,您实际上是在强迫它
看起来像是更多值的来源(因此隐式地将其转换为最佳的IEnumerable
匹配,这是IEnumerable
)很高兴能提供帮助。还请查看更详细的编辑:)很高兴能提供帮助。请查看更详细的编辑:)