Convert the code into lambda/LINQ(C#3.0)

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-05-19T04:13:04Z Indexed on 2010/05/19 4:20 UTC
Read the original article Hit count: 160

Filed under:

How to convert the below code into lambda

if (ds != null && ds.Tables.Count > 0)
            {
                dtAsset = ds.Tables["AssetData"];
                dtCharecteristics = ds.Tables["CharacteristicsData"];

                for (int i = 0; i < dtAsset.Rows.Count; i++)
                {
                    for (int j = 0; j < dtCharecteristics.Rows.Count; j++)
                    {
                        if (dtAsset.Rows[i]["AssetId"].Equals(dtCharecteristics.Rows[j]["AssetId"]))
                        {
                            objAttributesCollection.Add(new Attributes
                            {
                                AttributeCode = Convert.ToString(dtCharecteristics.Rows[j]["AttributeCode"]),
                                TimeSeriesData = fn(Convert.ToDateTime(dtCharecteristics.Rows[j]["StartDate"]), Convert.ToString(dtCharecteristics.Rows[j]["Value"]))
                            });  

                        }
                    }
                    objAssetCollection.Add(new Asset
                    {
                        AssetId = Convert.ToInt32(dtAsset.Rows[i]["AssetId"]),
                        AssetType = Convert.ToString(dtAsset.Rows[i]["AssetCode"]),
                        AttributeCollection = objAttributesCollection
                    });
                    objAttributesCollection = new List<Attributes>();
                }
            }

I am using C#3.0

There is nothing wrong in the code but for the sake of learning I want to do this.

Thanks

© Stack Overflow or respective owner

Related posts about c#3.0