Comment convertir le code ci-dessous dans lambdaConvertir le code dans lambda/LINQ (C# 3.0)
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>();
}
}
J'utilise C# 3.0
Il n'y a rien de mal dans le code, mais pour la l'amour d'apprendre je veux faire ceci.
Merci
AsEnumerable est une méthode d'extension. Vous n'avez pas besoin d'écrire "DataTableExtensions.AsEnumerable (table)" - écrivez simplement "table.AsEnumerable()". –