score:1
Accepted answer
that's should what you are looking for :
(i love to use string.isnullorempty
rather than cmp string.empty)
_targethasmissingratings = _existingratings.any(er => string.isnullorempty(_targetratings.firstordefault(tr => er.ratingtypeid == tr.ratingtypeid)?.rating));
score:1
use icomparable so you can use orderby on the entire class or simply compare two instances of the class.
list<ratingdto> ordered = _existingratings.orderby(x => x).tolist();
see code below :
class ratingdto : icomparable<ratingdto>
{
public int ratingtypeid { get; set; }
public string ratingtype { get; set; }
public string rating { get; set; }
public int compareto(ratingdto other)
{
if (this.ratingtypeid != other.ratingtypeid)
{
return this.ratingtypeid.compareto(other.ratingtypeid);
}
else
{
return this.ratingtype.compareto(other.ratingtype);
}
}
}
code would look like this :
list<ratingdto> _existingratings = new list<ratingdto>();
list<ratingdto> _targetratings = new list<ratingdto>();
boolean _targethasmissingratings = false;
foreach (var existing in _existingratings)
{
foreach (var target in _targetratings)
{
if (existing == target)
{
_targethasmissingratings = true;
break;
}
}
if (_targethasmissingratings == true) break;
}
Source: stackoverflow.com
Related Query
- Improve comparing between two collections - LINQ? C#
- Comparing two collections with IEquatable while using only LINQ
- Linq statement to select common elements between two collections
- LINQ query to find common strings between two collections
- Can I use LINQ to compare what is missing, added or updated between two collections
- LINQ to SQL - Filtering the dataset between two nested collections
- Get the difference between two lists using LINQ
- How to search between two dates in LINQ to Entity?
- LINQ way to get items between two indexes in a List
- How to concatenate two collections by index in LINQ
- Match elements between 2 collections with Linq in c#
- Linq query between two list objects
- LINQ to SQL value BETWEEN two double values
- LINQ Comparing Two Lists - Add new, remove old, leave the ones in common
- Filter data between two dates using LINQ
- How to sum Timespan of subtraction between two datetimes in Linq when using group by?
- LINQ Source Code Available
- Count matching characters between two strings using LINQ
- How can I combine this code into one or two LINQ queries?
- LINQ Union between two tables with the same fields and then returned in a collection
- Date range falling between two dates in a LINQ query
- Difference between the returned values of two selector functions in this code
- LINQ for comparing two lists with complex entities
- Overlapping records between two dates using Linq
- Linq to compare two collections in C#
- C# / LINQ fastest way of comparing two lists and assigning value
- Get a sequence of multiples of an integer between two values using LINQ
- VB.Net LINQ - left outer join between two datatables - limit to one row
- How to use LINQ to combine two or more collections into one collection
- Comparing two lists using linq to sql
More Query from same tag
- Is it efficient to use LINQ to parse strings?
- Concat a enum with a string in a linq query
- A more efficient way of showing adds/deletes in a context
- LINQ for querying a DTO for a specific Name-Value pair in a generic and recursive manner
- LINQ group by on data service
- ArrayAccess vs. ArrayIndex in Expression Tree
- Linq Expression For DateTime Equality Nullable Issue
- Join, Group By and Aggregate with LINQ
- Using LINQ in foreach loop declaration
- Date Format in C# Linq
- Linq select one occurrence
- Need to Include() related entities but no option to do so
- Can I use LINQ GroupBy to do this more cleanly?
- Grouping, dynamic key formation, pivitoing information in C# & generating json output
- LINQ join query with ICollection
- LINQ query on a DataTable
- Filter data using LINQ from two table
- Select an element from a list of list
- Am I using the LINQ .OfType() operator correctly?
- Expression to create instance and set members not using MemberInit
- Dynamic Linq Where with Lambda Expression generates Error
- Where can I view LINQ source code?
- select all related objects
- Why does an IF Statement effect the outcome of my LINQ Statement?
- how to count and group by using linq
- using Single/First methods to return multiple values in linq or lambda expression
- Get max attribute value from XML using LINQ
- How to convert two columns into a single string column with dynamic linq?
- Generic list in an interface
- How to Get All records with specific Id and LastDate