views:

29

answers:

2
private List<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?

+1  A: 

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.

Dewfy
This seems to work until I try to query against it using LINQ. I get an error "Could not find an implementation of the query pattern for source type 'System.Collection.IList'. 'Where' not found. Consider explicitly specifying the type of the range variable 'l'.var list = GetFieldList();var item = (from l in list where l.DisplayName = ddlFields.SelectedValue select l).SingleOrDefault();
Jhorra
@Jhorra, the cast not to IList, but IEnumerable
Dewfy
+1  A: 

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.

Jhorra