Hi siddangoud,
Check this example. Now please take its reference and correct your code.
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
var r1 = new List<Hobby>()
{
new Hobby { hobbyid=1, hobbyName="cricket", isactive=true },
new Hobby { hobbyid=2, hobbyName="chess", isactive=true }
};
var r2 = new List<Hobby>()
{
new Hobby { hobbyid=1, hobbyName="cricket", isactive=false },
new Hobby { hobbyid=2, hobbyName="chess", isactive=false },
new Hobby { hobbyid=3, hobbyName="swim", isactive=false },
};
var r3 = new List<Hobby>();
foreach (Hobby hobby in r2)
{
var item = r1.Where(c => c.hobbyid == hobby.hobbyid).FirstOrDefault();
if (item != null)
{
//If exist, update the isactive.
item.isactive = hobby.isactive == true ? hobby.isactive : item.isactive;
r3.Add(item);
}
else
{
//Add new hobby.
r3.Add(hobby);
}
}
}
public class Hobby
{
public int hobbyid { get; set; }
public string hobbyName { get; set; }
public bool isactive { get; set; }
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim r1 = New List(Of Hobby)() From {
New Hobby With {.hobbyid = 1, .hobbyName = "cricket", .isactive = True},
New Hobby With {.hobbyid = 2, .hobbyName = "chess", .isactive = True}
}
Dim r2 = New List(Of Hobby)() From {
New Hobby With {.hobbyid = 1, .hobbyName = "cricket", .isactive = False},
New Hobby With {.hobbyid = 2, .hobbyName = "chess", .isactive = False},
New Hobby With {.hobbyid = 3, .hobbyName = "swim", .isactive = False}
}
Dim r3 = New List(Of Hobby)()
For Each hobby As Hobby In r2
Dim item = r1.Where(Function(c) c.hobbyid = hobby.hobbyid).FirstOrDefault()
If item IsNot Nothing Then
item.isactive = If(hobby.isactive = True, hobby.isactive, item.isactive)
r3.Add(item)
Else
r3.Add(hobby)
End If
Next
End Sub
Public Class Hobby
Public Property hobbyid As Integer
Public Property hobbyName As String
Public Property isactive As Boolean
End Class
Screenshot