How do I use LINQ to obtain a unique list of properties from a list of objects?
IEnumerable<int> ids = list.Select(x=>x.ID).Distinct();
IEnumerable<int> ids = list.Select(x=>x.ID).Distinct();
Most of what you do in programming all day is combining some functions together to build bigger functions from them. Usually you have not only functions in your toolbox but also other things like operators, variable assignments and the like, but generally your program combines together lots of “computations” to bigger computations that will be … Read more
Delayed execution
Lambda expressions are a simpler syntax for anonymous delegates and can be used everywhere an anonymous delegate can be used. However, the opposite is not true; lambda expressions can be converted to expression trees which allows for a lot of the magic like LINQ to SQL. The following is an example of a LINQ to … Read more
You can use XDocument.Parse for this.
myCars.Select((v, i) => new {car = v, index = i}).First(myCondition).index; or the slightly shorter myCars.Select((car, index) => new {car, index}).First(myCondition).index; or the slightly shorter shorter myCars.Select((car, index) => (car, index)).First(myCondition).index;
Mine would be this in c# 3.0 🙂 var type = typeof(IMyInterface); var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => type.IsAssignableFrom(p)); Basically, the least amount of iterations will always be: loop assemblies loop types see if implemented.
IEnumerable<Customer> filteredList = originalList .GroupBy(customer => customer.CustomerId) .Select(group => group.First());
I just had the same problem. Visual Studio isn’t building the project that’s being referenced. Written Instructions: Right click on the solution and click Properties. Click Configuration on the left. Make sure the check box under “Build” for the project it can’t find is checked. If it is already checked, uncheck, hit apply and check … Read more