Tuesday, January 29, 2019

c# - Why we should use IEnumerable instead of something else?

I have some rows of code:



public IEnumerable GetCardNames()
{
string[]cardname = new string[cards.Count];

for (int i = 0; i < cards.Count; i++)
cardname[i]= cards[i].value + " of " + cards[i].suit + "\n";

return cardname;
}


What I confused about is why it's a better way to use:



public IEnumerable GetCardNames()


than :




public string[] GetCardNames()


or :



public List GetCardNames()


I have read a lot of answers about IEnumerable but I'm still not feel so clear about this one, I mean the benefit of using IEnumerable in this case.

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...