c# - What ReadOnlyCollection type should methods return? -


i've seen returning 'ilist' vs 'icollection' vs 'collection' , other questions links to, i'm still confused issue.

let's assume demonstration purposes have class, expose public method, follows:

public readonlycollection<type> getreadonlycollection(ienumerable<type> enumerable) {     list<type> list = enumerable.tolist();     return new readonlycollection<type>(list); } 

to follow ca1002, should method return actual collection classes (readonlycollection, collection, etc.) or their interfaces (ilist, icollection, etc.) if wish return readonlycollection specifically?

you gain flexibility later change implementation if return type general possible. of course have return type useful consumer. hence, returning interface type better, , more general type well, long not cause problems in usage on consumer side.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -