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

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

    It depends.

    Do you want the caller to be able to modify the items and for you to see those changes? Arrays can be modified. The IList interface defines methods for modification (but the implementation may not allow it).

    Can you elaborate on the FxCop warning?

    Kent

提交回复
热议问题