Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have model class look like

   public class Student
   {
       public string student_id{ get; set; }
       public string student_name{ get; set; }
       public string father_name{ get; set; }
   }
 public class StudentStatus
   {
       public string student_id{ get; set; }
       public string session{ get; set; }
       public string status{ get; set; }
   }
public class FinalList
   {
       public string student_id{ get; set; }
       public string student_name{ get; set; }
       public string father_name{ get; set; }
       public string session{ get; set; }
       public string status{ get; set; }
   }


and i have two List also
List<Student> std1=new List<Student>()
{
new Student{student_id="1",student_name="test1",father_name="father1"},
new Student{student_id="2",student_name="test2",father_name="father2"}
}

List<StudentStatus> std2=new List<StudentStatus>()
{
new Student{student_id="1",session="2021",status="Active"},
new Student{student_id="2",session="2022",status="InActive"}
}


now i want to merge the data of this two List into 3rd List. and my final list should be look like this:


List<FinalList> finallist=new List<FinalList>()
{
new Student{student_id="1",student_name="test1",father_name="father1",session="2021",status="Active"},
new Student{student_id="2",student_name="test2",father_name="father2",session="2022",status="InActive"}
}


any one suggest me the solution

What I have tried:

i google it but only find solution for string or int type list not classobject type list like this

1. firstList.AddRange (secondList);

2. var combined = list1.Concat(list2);

this solution does not work in my case
Posted
Updated 19-Sep-22 20:29pm
v2
Comments
Richard MacCutchan 20-Sep-22 3:41am    
You need to get the records from each list in student_id order. You can then read the matching records from each list to merge them into the final list.
TCS54321 20-Sep-22 3:57am    
thanx for your reply. but i got the better solution. i used linq query with join and assign the query result into my final list.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900