返回null或空集合更好吗?
这是一个普遍的问题(但是我正在使用C#),最好的方法是什么(最佳实践),对于以集合为返回类型的方法,您是否返回null或空集合? #1楼 我想在这里举例说明。 在这里考虑一个案例。 int totalValue = MySession.ListCustomerAccounts() .FindAll(ac => ac.AccountHead.AccountHeadID == accountHead.AccountHeadID) .Sum(account => account.AccountValue); 在这里考虑我正在使用的功能.. 1. ListCustomerAccounts() // User Defined 2. FindAll() // Pre-defined Library Function 我可以轻松地使用 ListCustomerAccount 和 FindAll 代替。 int totalValue = 0; List<CustomerAccounts> custAccounts = ListCustomerAccounts(); if(custAccounts !=null ){ List<CustomerAccounts> custAccountsFiltered = custAccounts.FindAll(ac => ac.AccountHead