Data access level: display list <>: bad idea?

I am currently encoding a simple level of data access, and I was wondering what type I should open to other layers.

I am going to internally implement Data as a list <>, but I remember reading something about not exposing the List type to consumers if they are not needed.

public List<User> GetAllUsers() // non C# users: that means List of User :)

Do you know why (Google didn't help)? What do you usually post for this kind of thing? IList? IEnumerable?

+3
source share
3 answers

, . , IEnumerable<User>. , ( ), IList<User>.

/EDIT:

: ? ()

, , , , : - , . , . , .

, . , IList, : , . .

, Values, IList.

+6

ISomething. . . IList , ICollection , ReadOnly.

+3

, IEnumerable. "" IEnumerable LINQ, .

IEnumerable IEnumerable, . IList, , IEnumerable.

On the other hand, returning IList implies that the caller can modify the returned list.

+2
source

Source: https://habr.com/ru/post/1698262/


All Articles