How can I get a value of a property from an anonymous type?

后端 未结 12 1273
南旧
南旧 2020-12-24 08:34

I have a datagrid populated by a Linq query. When the focused row in the datagrid changes I need to set a variable equal to one of the properties in that object.

I t

12条回答
  •  青春惊慌失措
    2020-12-24 09:33

    Hope this helps, am passing in an interface list, which I need to get a distinct list from. First I get an Anonymous type list, and then I walk it to transfer it to my object list.

    private List GetDistinctSymbolList( List l )
                {
                    var DistinctList = (
                            from a
                            in l
                            orderby a.Symbol
                            select new
                            {
                                a.Symbol,
                                a.StockID
                            } ).Distinct();
    
                    StockSymbolResult ssr;
                    List rl = new List();
                    foreach ( var i in DistinctList )
                    {
                                    // Symbol is a string and StockID is an int.
                        ssr = new StockSymbolResult( i.Symbol, i.StockID );
                        rl.Add( ssr );
                    }
    
                    return rl;
                }
    

提交回复
热议问题