[Solved] How to sum integer item in List?

Though the other answers supplied are effective enough, I would like to supply a thorough answer to assist at more than just the current syntactical level of C#. For example; Linq wasn’t available prior to 3.5. IS Keyword Checks if an object is compatible with a given type, or (starting with C# 7.0) tests an … Read more

[Solved] How to read lines to dictionary with linQ [closed]

The problem is that you need to provide a lambda expression for the second argument of ToDictionary. ToDictionary also returns a Dictionary<T, U> so you won’t be able to assign it to an instance of ConcurrentDictionary<T, U>. This should do the trick: var dicFailedProxies = File.ReadLines(“failed_proxies.txt”) .Distinct() .ToDictionary(line => line, line => 0); Of course, … Read more

[Solved] Linq join between two Lists [closed]

var result = studentList .Join(markList, m => m.Id, s => s.Sid, (s, m) => new { s, m }) .GroupBy(t => t.s) .Select(g => new { Student = g.Key, MarksCount = g.Count(), Marks = g.Select(x => x.m).ToList() }) .ToList(); MarksCount – total marks for this student Marks – List of marks for this student solved … Read more

[Solved] to get folders from directory between the dates entered in two textboxes

If you want to filter the files you are gonna iterate through, you can use System.IO‘s FileInfo class instead if File. Then you filter the files by their CreationDate property: DateTime yourstartDate = new DateTime(); DateTime yourEndDate = new DateTime(); DirectoryInfo di = new DirectoryInfo(“any_directory”); List<FileInfo> fis = di.GetFiles().Where(x => x.CreationTime >= yourstartDate && x.CreationTime … Read more

[Solved] Update xml node data, how [duplicate]

Try my solution, string xml = @”<categories> <category> <id>1</id> <name>Computer</name> <description>Information tech.</description> <active>False</active> </category> <category> <id>2</id> <name>Cate1</name> <description>MMukh</description> <active>True</active> </category> </categories>”; XDocument xDoc = XDocument.Parse(xml); int id = 1; var items = xDoc.XPathSelectElement(“//category[id=” + id + “]”) .Elements() .ToDictionary(e => e.Name.LocalName, e => (string)e); if (items != null) { // display these fields to the … Read more

[Solved] In c# where in clause works for integers?

If _ProjectContext.ProjectDetails has more then one phase item then it will throw exception. But if there is no matching element then it will return 0 var numbers = new[] {1 ,2, 3}; numbers.Where(x => x == 6).SingleOrDefault(); // returns 0 because default(int) == 0 1 solved In c# where in clause works for integers?

[Solved] Invoke Delegate With Right Type [closed]

Two options to consider: Use dynamic typing to call a generic method which will return you a Func<object, object> which you can use later by wrapping up an expression-tree-compiled delegate: public Func<Object, Object> CreateFunc(object sampleValue) { dynamic dynamicValue = sampleValue; return CreateFuncImpl(dynamicValue); // Dynamic type inference } private Func<Object, Object> CreateFuncImpl<T>(T sampleValue) { // You … Read more

[Solved] Write an INNER JOIN in LINQ

I think it is easier to translate SQL using query comprehension syntax instead of lambda syntax. General rules: Translate inner queries into separate query variables Translate SQL phrases in LINQ phrase order Use table aliases as range variables, or if none, create range variables from table names abbreviations Translate IN to Contains Translate SQL functions … Read more

[Solved] Reading A Fixed Format Text File – Part 3

You have not initialized MyDataTable by a data after instantiation, you have filled in data set but not a data table. So just try out MyDataSet.Tables[0] instead of MyDataTable.AsEnumerable() // DataSet filled in but data table still empty! MyDataAdapter.Fill(MyDataSet,”STUFF”); 1 solved Reading A Fixed Format Text File – Part 3