What's the return type of an anonymous class

前端 未结 7 2360
再見小時候
再見小時候 2020-12-11 09:28

I have a class that used to have a string return type. Now I find I need to return more than a string. I was thinking to return something like below:

public          


        
7条回答
  •  粉色の甜心
    2020-12-11 10:05

    You can make a struct (or class) for this.

    public struct IdAndName
    {
        public int Id;
        public string Name;
    
        public IdAndName(int id, string name)
        {
            ID = id;
            Name = name;
        }
    }
    

    You could also use a Tuple, (but that's not recommended as the properties aren't named.

提交回复
热议问题