What's the Best Way to Add One Item to an IEnumerable?

前端 未结 6 1510
余生分开走
余生分开走 2021-01-01 09:43

Here\'s how I would add one item to an IEnumerable object:

//Some IEnumerable object
IEnumerable arr = new string[] { \"ABC\", \"DEF\"         


        
6条回答
  •  独厮守ぢ
    2021-01-01 10:26

    You're assigning an array to an IEnumerable. Why don't you use the Array type instead of IEnumerable?

    Otherwise you can use IList (or List) if you want to change the collection.

    I use IEnumerable only for methods params when I need to read and IList (or List) when I need to change items in it.

提交回复
热议问题