standards-c-sharp

Collections types for non-public API methods

We define a non-public API method as:

Return types for non-public API methods

Do not return IEnumerable<T>, except if one of the following is true:

When none of the above are true:

Don’t

// unnecessary downcast on private method hides a bunch of functionality
private IEnumerable<string> GetStrings()
{
    return new List<string>{ ... };    
}

Do

// expose the original functionality, but through an interface to make it
// easier to change the implementation later
private IList<string> GetStrings()
{
    return new List<string>{ ... };    
}