i'm having a problem with merging two list of object here they are:
first one
List<NSKData> NSKDataList = new List<NSKData>();
public class NSKData
{
public string ID { get; set; }
public string Issue { get; set; }
public string ToolTipInfoText { get; set; }
public NSKData() { }
public NSKData(string id, string issue, string tooltipinfo)
{
ID = id;
Issue= issue;
ToolTipInfoText = tooltipinfo;
}
}
second one
List<IssuesMoreInfo> IssuesMoreInfoList = new List<IssuesMoreInfo>();
public class IssuesMoreInfo
{
public string ID { get; set; }
public string IssueMoreInfoText { get; set; }
}
If i can get all needed data at one time, i wont ask this question, but i'm grabbing all data for fist one, and only after i can get data for second one.
So, what i need in result is: to get IssueMoreInfo from second one, according to ID in both, like for id 10 in first one, we getting IssueMoreInfoText column in second one and pass it to firt one list in column ToolTipInfoText
Hope for your help, guys, thanks
One simple and popular way to merge(join) two lists in Python is using the in-built append() method of python. The append() method in python adds a single item to the existing list. It doesn't return a new list of items. Instead, it modifies the original list by adding the item to the end of the list.
util. ArrayList appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator. Using this method you can concatenate two lists.
The append function joins two lists together to make one. The append function is built into Scheme. It concatenates two lists, that is to say, given two lists list1 and list2 it produces a new list which starts with the same elements as list1 and finishes with those of list2 .
I assume you're looking for Enumerable.Join
:
var query = from data in NSKDataList
join info in IssuesMoreInfoList
on data.ID equals info.ID
select new NSKData(data.ID, data.Issue, info.IssueMoreInfoText);
NSKDataList = query.ToList();
Another way which does not need to re-create all objects and the list:
var infoIdLookup = IssuesMoreInfoList.ToLookup(i => i.ID);
foreach(NSKData data in NSKDataList)
{
data.ToolTipInfoText = infoIdLookup[data.ID]
.Select(i => i.IssueMoreInfoText)
.FirstOrDefault();
}
Try using Linq Join
var query = from c in NSKDataList
join o in IssuesMoreInfoList on c.ID equals o.ID
select new { c.ID, c.Issues , c.ToolTipInfoText , o.IssueMoreInfo };
The query will contains info from both of the lists
http://www.dotnetperls.com/join
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With