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

后端 未结 8 926
灰色年华
灰色年华 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:27

    I almost always go with List because it gives me methods that I frequently find the most useful.

    One potential negative consequence of returning an IEnumerable is that any exceptions that get thrown upon enumeration would come from an area of code that could be quite far away from the code that actually built the object, making bug tracking harder.

提交回复
热议问题