初學者問題。返回類型爲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''的類是 –