最佳的C#泛型类的替代数据表的集合? [英] Best c# generics class for replacing DataTable as collection?

查看:168
本文介绍了最佳的C#泛型类的替代数据表的集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把一个传统的C#.net 1.1应用到现代的时代。我们使用数据表为我们的什么可能是业务对象的集合。

I'm trying to bring a legacy C# .NET 1.1 application into the modern era. We use DataTables for our collections of what could have been business objects.

由于大部分的code认为它是跟一个DataRow的,什么泛型集合将使用于最不痛苦的过渡?

Given that most of the code thinks it is talking to the interface of a DataRow, what generic collection would make for the least painful transition?

推荐答案

如果即时阅读您的问题正确,你所要求的该容器将只储存你的业务对象的列表,然后让你只通过集合枚举,或者通过索引选择。

if im reading your question rightly, you are asking for which container will just store a list of your Business objects and then allow you to just enumerate through the collection, or select via an index.

好,我会考虑寻找到列表<>

well I would consider looking into the List<>

在这里,你的方法会接受任何的IList&LT;>(访问该指数)或的IEnumerable&LT;>(使用foreach循环的集合)

where you methods would accept either IList<> (to access the index) or IEnumerable<> (to use a foreach loop on the collection)

例如

private void PrintAll<T>(IEnumerable<T> items)
{
    foreach(T item in items)
        Console.WriteLine(item.ToString());
}

现在我可以将它使用了IEnumerable - 的任何容器;>接口,包括目录&LT;>和普通阵列

now i can pass in any container which uses the IEnumerable<> interface, including List<> and the normal array

例如

List<Person> people = new List<Person>();
//add some people to the list
PrintAll<Person>(people);

与理财周报样本的N层应用对象

心连心

这篇关于最佳的C#泛型类的替代数据表的集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆