Return Anonymous Type from a function

前端 未结 6 1005
庸人自扰
庸人自扰 2020-12-16 11:05

Can I use an anonymous type as a return type in a Function, and then stuff that returned value into an array or collection of some sort whilst also adding an additional fiel

6条回答
  •  情深已故
    2020-12-16 11:58

    No, you can't return an anonymous type directly, but you can return it using an impromptu interface. Something like this:

    public interface IMyInterface
    {
        string GroupName { get;  }
        int RowSpan { get; }
    }
    
    private IEnumerable GetRowGroups()
    {
        var list =
            from item in table
            select new
            {
                GroupName = groupedTable.Key.column1,
                RowSpan = groupedTable.Count()
            }
            .ActLike();
    
        return list;
    }
    

提交回复
热议问题