I have a situation where i want to return List<> from this function
public DataTable GetSubCategoriesBySubCatID(Guid SubCategoryID)
So what i want is
public List<SubCategories> GetSubCategoriesBySubCatID(Guid SubCategoryID)
I know overloading is not supported on the basis of return type only,I just donot want to duplicate same code in both functions.
Whats the best way to achieve this without impacting the references which hold true for first function
Give them different names:
public DataTable GetSubCategoryTableBySubCatID(Guid subCatID)
public List<SubCategory> GetSubCategoryListBySubCatID(Guid subCatID)
Aside from anything else, that will make it clearer which method you're interested in when you're reading the calling code.
If those should be implemented in a common way, write a private method containing the common core, and call it from both of the public methods. For example, you might use a delegate to do the "I've found a result, add it to your collection" part, or use an iterator block:
// "action" will be called on each sub-category
private void FindSubCategoriesBySubCatID(Guid subCatID,
Action<SubCategory> action)
private IEnumerable<SubCategory> FindSubCategoriesBySubCatID(Guid subCatID)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With