c# - how to merge / join two different list into 1 -
I am working on an application for the Windows Phone Platform. Run in a question.
I had 2 different lists, 1 is read directly from the XML file, and by some other calculations. And I want to merge these two lists into 1, so I can display it.
List 1:
public class studentClass1 {public string studentID {get; Set; } Public String Student FirstName {get; Set; } Public string studentListName {get; Set; }} list 2:
public class studentClass2 {public string studentID {get; Set; } Public String StudentGradePoint {Received; Set; }} First of all, I had read studentClass1
var studentList = through the studentInndex.Descendants ("student") select new drivers Student List 1 = Student List. ToList (); Secondly, I calculate the function and output of the student grade points in the second list:
studentClass2 SG = new student class 2 {studentID = thestudentID , StudentGradpoint = thestudentGradePoint.ToString ()}; StudentList2.Add (SG); StudentListAll = StudentList1 + StudentList2 Now, I want to include this two list together so that I can call it and output it on the screen
studentResultListBox.Itemsource = StudentListAll; How does a suggestion code look? Thank you.
After
Assume that you just want to combine the proper information of both the lists (from this completely Your question is not clear) - A third class introduction studentClass3 holds all the properties you want and using one to join examples to match with a studentID : on studentList3 = (s2.stude to join s1.studentID in s2 studentList2 in studentList1 The ntID selection is equivalent to the new studentClass3 () {studentFirstName = s1.studentFirstName, studentID = s1.studentID, studentGradePoint = s2.studentGradePoint, studentLastName = S 1. StudentListName}). ToList (); Usually this problem should be solved when you are trying to combine lists later in XML - for students, three different classes may be confusing, besides recommended. Take a look at the naming conventions, they are a bit far away.
Comments
Post a Comment