C# List vs IEnumerable performance question

后端 未结 4 2035
伪装坚强ぢ
伪装坚强ぢ 2021-02-12 14:55

Hi suppose these 2 methods:

private List GetProviderForType(Type type)
        {
            List returnValue = new         


        
4条回答
  •  感动是毒
    2021-02-12 15:12

    The Main Difference Between IEnumerable and IList:

    IEnumerable: Implements MoveNext,Reset,Get Current Methods and Returns a Type of IEnumerator to Iterate Through Records.

    IList : Exposes the IEnumerable Interface as well as it is also a collection of non-generic objects which can accessed through index so IEnumerable+ICollection(Manipulation of data) and add,remove,Insert(at specific Index) are the useful methods implemented by IList.

    After looking at your Code In My Opinion IEnumerable is more efficient but returning list is also useful if you want to do some manipulation with data and if you just want to Iterate through data then IEnumerable is preferable.

提交回复
热议问题