LINQ Examples

Examples LINQ
// LINQ Dir with Files
IEnumerable<FileInfo> files = from file in new DirectoryInfo(path).GetFiles()
                              where file.Name.StartsWith("_")
                              select file;
foreach (FileInfo file in files)
{
   .....
}

// LINQ Dictionary
var dd = new Dictionary<float, int>();
IEnumerable<float> maxVersion = (from k in dd_.Keys
                                 orderby k descending
                                 select k).Take(1);

var percentages = dd.Select(kvp => new {Text = kvp.Key, Percent = Math.Round
(kvp.Value*100/sum)}).OrderByDescending(s => s.Text); foreach (var enumerable in percentages) { yValues.Add(enumerable.Percent); xValues.Add(enumerable.Percent + "%"); LegendTexte.Add(enumerable.Text.ToString()); } // LINQ XML XDocument loaded = XDocument.Load("file.xml"); var q = from c in loaded.Descendants("section") select new {title = c.Element("title").Value,
img = c.Element("img").Value, text = c.Element("text").Value} ; foreach (var item in q) .....


Comments are closed