初学者问题。返回类型为datatable或List - c#
有DAL类在我的应用程序,它具有以下功能
public static Datatable GetCustomers()
public static Datatable GetOrderDetails(int orderId)
我已经被告知,良好的做法是,返回类型为List或类。
所以这将是
public static List<customer> GetCustomers()
{
Datatable dt = ...;
//then loop through the rows in the table and add to List<customer>
}
public static order GetOrderDetails(int orderId)
我想知道什么是在后发优势。
有一个'List'你可以用LINQ稍后过滤它,连接到WPF中的项目控件等。 –
对于初学者来说,它将从接口中分离实现(使用数据表)。这样可以更轻松地进行单元测试,并允许更改而不影响客户端。你也可以返回一个'IEnumerable'而不是列表。 –
''List'1''是类似''Datatable''的类是 –