[Solved] How to re-write this linq from query syntax to method syntax? [closed]

You could try something like this: recordsEpP.Where(row=> !string.IsNullOrEmpty(row.Column20) && !string.IsNullOrEmpty(row.Column14) && string.IsNullOrEmpty(row.Column8) ).Select(row => new ReportDto{ Status = “P”, ContractNumber = row.ContractNumber, Count = 1 }).ToList(); 0 solved How to re-write this linq from query syntax to method syntax? [closed]

[Solved] Use linq distinct function? [duplicate]

You could use GroupBy on an anonymous type with both properties to make them distinct: var coursesList = from c in not_subsribe group c by new { Id = c.Cours.ID, Name = c.Cours.Name } into g order by g.Key.Name select new SelectListItem { Text = g.Key.Name, Value = g.Key.Id }; That works because an anonymous … Read more

[Solved] Get All instead of FirstOrDefault

You are using FirstOrDefault so you are returning only the first. PromotionList dataPromotion = authenticateCustomerResponseRootObject.Response.AuthenticateCustomerResponse.EligiblePromotions.PromotionList.Where(p => p.LineOfBusiness.ToUpper().Equals(“Data”)).FirstOrDefault(); If you want all of them just remove that call at the end and replace with a ToList, ToArray or similar that meets your needs: var data = authenticateCustomerResponseRootObject.Response.AuthenticateCustomerResponse.EligiblePromotions.PromotionList.Where(p => p.LineOfBusiness.ToUpper().Equals(“Data”)).ToList(); Also as mentioned in the comments your … Read more

[Solved] Seeking feedback on my design of LINQ expressions [closed]

You’re comparing apples and oranges. Each of the approaches you list has benefits and drawbacks, so it’s impossible to answer which is the “preferred way.” Likewise, many of these examples will return immediately because they use deferred execution, so they’ll technically run faster, but won’t actually make your program run any faster. But if you’re … Read more

[Solved] Delete object single property from list

This cannot be done because once the class definition is set, that’s it. The best you can do to retrieve an array of only the Name and Address properties contained in an object is to use LINQ to perform an operation on each element, in which case you can then retrieve an array of anonymous … Read more

[Solved] Next permutation algorithm c# and linq [closed]

You could try following code, it uses private field to stroe all permutations generated by methods finding permutations: private static List<string> _permutations = new List<string>(); public static Main(string[] args) { string testString = “abc”; TestMethod(testString); // You need to handle case when you have last permuation in a list string nextPermutation = _permutations[_permutations.IndexOf(testString) + 1]; … Read more

[Solved] C# + get list from list [closed]

var summary = FullList .GroupBy(p => p.product_id) .Select(g => new { product_id = g.product_id, product_name = g.First().product_name, quantity = g.Sum(p => p.quantity) }) .ToList(); As an exercise think about Concat for getting all the depot names. 2 solved C# + get list from list [closed]

[Solved] How can you select and filter dictionary keys based on their values using Linq?

there can ba multiple values that match the condition – Dictionary<int, decimal> dict = new Dictionary<int,decimal>(); dict.Add(1, 392.3m); dict.Add(2, 612m); dict.Add(3, 981m); dict.Add(4, 344.23m); List<int> Result = dict.Where(x => x.Value < 400).Select(x => x.Key).ToList(); 0 solved How can you select and filter dictionary keys based on their values using Linq?

[Solved] How to compare two list of object in c#

public class ClassBEqualityComparer : IEqualityComparer<ClassB> { public bool Equals(ClassB x, ClassB y) { if((x.var2.Equals(y.var2)) && (x.var3.SequenceEqual(y.var3)) && (x.var4.SequenceEqual(y.var4))) { return true; } else { return false; } } public int GetHashCode(ClassB x) { } } public class ClassAEqualityComparer : IEqualityComparer<ClassA> { public bool Equals(ClassA x, ClassA y) { ClassBEqualityComparer ClassBEqC = new ClassBEqualityComparer(); if((x.Type == … Read more

[Solved] Which is faster, for loop or LINQ

Neither. Using a loop has less overhead than LINQ, so that is a good start. Use the < operator in the loop condition, that is the standard way of writing such a loop, so it’s more likely that the compiler will recognise it and optimise it properly. Using Math.Pow to square a number is not … Read more

[Solved] Average of empty list throws InvalidOperationException: Sequence contains no elements [closed]

Not much to it – it’s just how the code was written. Take a look at the docs and you’ll see – Exceptions ArgumentNullException – source is null. InvalidOperationException – source contains no elements. Makes sense though. You can’t get an average from zero items. 2 solved Average of empty list throws InvalidOperationException: Sequence contains … Read more