score:3
Accepted answer
you could also try this
var listcoord = new list<coord>();
dictionary<string, string> dict = new dictionary<string, string>();
dict.add("a", "myvalues");
listcoord.add(new coord
{
segment = "a",
});
listcoord.add(new coord
{
segment = "b",
});
listcoord.add(new coord
{
segment = "c",
});
list<coord> result = listcoord.where(cords => dict.containskey(cords.segment))
.tolist();
use
containskey
and/orcontainsvalues
based on your requirement.
sample working available at dotnetfiddle
thanks for the catch @yacoub massad
score:7
this is the way to join list & dictionary (you will get only matching coords)
list<coordnew> newlist = listcoord .join(strdictionary,
a => a.segment, //from listcoord
b => b.key, //from strdictionary
(a, b) => new coordnew() {
segment_dictionaryvalue = b.value
//other values from list or dictionary
}).tolist();
if you need coordnew
as
class coordnew
{
public string segment { get; set; }
public string segment_dictionaryvalue { get; set; }
public double startx { get; set; }
public double starty { get; set; }
public double endx { get; set; }
public double endy { get; set; }
}
Source: stackoverflow.com
Related Query
- Joining Dictionary key that matches class List's list item into a new list - C#
- How to merge two lists of different types into one list of new type that contains both types?
- Merge two Lists in C# and merge objects with the same id into one list item
- Using Linq to group a list of objects that contains primitives data into a new grouped list of objects
- How to select objects from a list that has a property that matches an item in another list?
- Divide a single List of Class Objects into multiple Lists based on Class Members C#
- how split the List of strings into another Lists if particular string matches condition using linq?
- How to Zip two Lists of different size to create a new list that is same as the size of the longest amongst the original lists?
- Optimizing LINQ combining multiple lists into new generic list
- C# LINQ how to flatten parent list and two nested children lists into a new list
- Separate a list of objects into multiple lists that only contain unique items
- Compare two lists - If any objects property in one list have changed or a new object in list been added, return that object
- Finding duplicate lists in dictionary and print Key of the duplicated list
- Using linQ to group list of object into new lists of objects
- C# LINQ merging list and dictionary into new dictionary
- LINQ: Load XML into a Dictionary with value equaling new custom class instances
- Compare 2 lists of objects and create a new list based off item properties in the first list not being present in the second with ASP.NET
- Given two lists of different objects, how to combine values from each into a new list based on a common Id, efficiently?
- Comparing two lists and removing each item that contains an entry from the other list
- How to Group List into new class with sub list class
- LINQ adding new item (student) to a list of another type (courses) using a connector class
- Full outer join two lists of separate classes into a third list of a third class
- Merging a list into a Dictionary with a dynamic key type
- Using Linq to group a list of objects into a new grouped list of list of objects
- Map two lists into a dictionary in C#
- LINQ Partition List into Lists of 8 members
- Convert an array to dictionary with value as index of the item and key as the item itself
- LINQ return items in a List that matches any Names (string) in another list
- Split a list into multiple lists at increasing sequence broken
- Merge multiple Lists into one List with LINQ
More Query from same tag
- Group by generates a huge query
- How do I get a list of distinct rows from the result of multiple joins in Linq?
- Linq Expression to Query Two List
- How to Dynamically edit list of object linq c#
- Why does a GC after a LINQ query free the WhereListIterator but not the Func representing the condition?
- Store update LINQ query and pass to json
- Can I change an XText object into a string with character references and entities resolved?
- How to convert foreach into linq queries or lambda expression
- C# LINQ - Find object in list between two properties
- LINQ DefaultIfEmpty issue on object with non-nullable value type property
- Does LINQ AsParallel() preserve thread safety?
- Entity Framework Non static method needs a target. Null values in Lambda
- Linq to SQL valid Contacts in each Customer
- Foreach in Linq
- Linq _ If one parameter is null then return empty or string
- How to pivot rows for an editable grid?
- SQL query with subquery equivalent for Linq-to-SQL
- Get max + min in one line with linq
- Get those elements from a List of custom class objects whose one property value is parseable to double
- How to select distinct with linq when comparing values
- How to add a where clause that looks for an array of values
- How to write Enumerable 'like' query using linq.js
- C# LINQ Generic Extension Method to check if sequence is the same and return it's value
- Get All record group by date and hour if any column have null value
- Error in IQueryable + foreach
- ToUpper() in an Expression.Call
- Parsing XML with LINQ in C#
- Adding a calculated field in LINQ select results?
- String split and spread the result across different arrays
- When to force LINQ query evaluation?