none
LINQ RRS feed

  • Question

  • hi

    how can i do something like that in LINQ,

    ObservableCollection<SimpleLayer> oCollection = new ObservableCollection<SimpleLayer> ( () => { for (int i = 0; i < bigLayers.Count; i++) { return new SimpleLayer(i /*layerId*/, bigLayers[i].Name, bigLayers[i].Color); } }

    // the next code not a solution cuz i want a counter //from layer in dxfAllLayers ////where true //select new SimpleLayer(1 /*layerId*/, layer.Name, AciColorToHex(layer.Color)) ) ;

    note: i don't want to use

    ObservableCollection<SimpleLayer> oCollection;
    
    for (int i = 0; i < bigLayers.Count; i++)
                        {
                            oCollectio.Add( SimpleLayer(1 /*layerId*/, dxfAllLayers[i].Name, bigLayers[i].Color));
                            }

    thanks in advance.



    • Edited by essamce Wednesday, February 12, 2020 4:01 PM
    Wednesday, February 12, 2020 3:46 PM

Answers

  • Try one of possibilities:

    var oCollection = new ObservableCollection<SimpleLayer>( bigLayers.Select( ( b, i ) => new SimpleLayer( layerId: i, bigLayers[i].Name, bigLayers[i].Color ) ) );
    

    • Marked as answer by essamce Wednesday, February 12, 2020 6:03 PM
    Wednesday, February 12, 2020 4:03 PM