Convert the code into lambda/LINQ(C#3.0)
- by Newbie
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