Best practice when returning an array of values (.NET)

后端 未结 8 763
灰色年华
灰色年华 2021-01-14 14:37

Usually my methods are as the following:

public List Method1(int input)
{
    var output = new List();
    //add some items to output
          


        
8条回答
  •  太阳男子
    2021-01-14 15:07

    Return the interface that you need in the code calling this method.

    If you need to do list actions on the result, return IList. If you just need to enumerate the results, return IEnumerable.

    Those are the ones I use most, actually. I never return arrays from public interfaces unless there's a very good reason for it.

提交回复
热议问题