开发者

A fast way to find a row that contains a specific object in a .NET DataTable

开发者 https://www.devze.com 2023-04-01 03:32 出处:网络
I have the following scenario: Public Class MyType { Public string A{ get;set;} Public string 开发者_运维百科B{ get;set;}

I have the following scenario:

Public Class MyType
{
   Public string A{ get;set;}
   Public string 开发者_运维百科B{ get;set;}
}
.....
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("myNode", typeof(MyType)));

What is the most efficient way to locate a row that holds a MyType where A = "specific value" other than doing a for each?


Datatable.rows has a find() method, however I've never been satisfied with the speed of it if you're dealing with a large datatable or many finds. If you're only dealing with 2 columns of data, have a look at using a hashtable instead. They are VASTLY faster when it comes to searching.


There is Select and find methods for datatable. May be you can use that.


I addition to what Jeff Bane proposed, consider filtering your data at the database level (SELECT ... WHERE ...). For truly gargantuan volumes of data, nothing beats the database.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号