Tuesday 29 January 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...