开发者

Question about using Anonymous List Types

开发者 https://www.devze.com 2023-01-01 14:50 出处:网络
private 开发者_StackOverflowList<T> GetFieldList() { var Fields = new { DisplayName = \"MCP\", FieldName = \"t.MCP\", FieldType = 1 };
private 开发者_StackOverflowList<T> GetFieldList()
{
    var Fields = new { DisplayName = "MCP", FieldName = "t.MCP", FieldType = 1 };
    var FieldList = (new[] { Fields }).ToList();

    return FieldList;
}

Should I be able to do something like this?


If I understand correctly your tag "asp.net" this construction will be used as part of data binding. Just use non generic :

private IList GetFieldList()
{
    var Fields = new { DisplayName = "MCP", FieldName = "t.MCP", FieldType = 1 };
    IList FieldList = (new[] { Fields }).ToList();

    return FieldList;
}

It would be nice handled by all data-bound controls.


I just realized I don't need to use an anonymous list as I know the structure of the data I'm expecting, so I'll just create a small class for it.

0

精彩评论

暂无评论...
验证码 换一张
取 消