LINQ铸造用Data.DataTableCollection [英] LINQ casting with a Data.DataTableCollection
本文介绍了LINQ铸造用Data.DataTableCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我使用到Data.DataTable由列数排序如下VB.NET code。
I have the following VB.NET code that I am using to sort a Data.DataTable by column count.
For Each dtTarget As Data.DataTable In _
From x In Target.Tables _
Where DirectCast(x, Data.DataTable).Rows.Count > 0 _
Order By DirectCast(x, Data.DataTable).Columns.Count
...
Next
有一种方法,以指示x被一个Data.DataTable无需它被引用(在这种情况下,两次)每次DirectCast它在LINQ查询?
Is there a way to indicate that x is a Data.DataTable without having to DirectCast it each time it is referenced (twice in this case) in the LINQ query?
推荐答案
是这样的:
Target.Tables.Cast<Data.DataTable>()
,然后让你的那个查询。而且你应该正确地重构你code成几行,以使其更具可读性。
and then make your query of that. And you should properly refactor you code into several lines to make it more readable.
(这是C# - 但我把它翻译,2秒)
(this is C# - but I will translate it, 2 sec)
翻译:
Dim query = From x In Target.Tables.Cast(Of Data.DataTable)() _
Where x.Rows.Count > 0 _
Order By x.Columns.Count _
Select x
For Each dtTarget As var In query
...
Next
这篇关于LINQ铸造用Data.DataTableCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文