I have two Class MyObjectA and MyObjectB
public class MyObjectA
{
private int A_ID {get; set;}
private int B_ID {get; set;}
.
.
.
.
}
public class MyObjectB
{
private int B_ID {get; set;}
.
.
.
.
public MyObjectB (int B_ID )
{
DAL.GetMyObjectBFromDatabase(B_ID );
}
}
Now what I am trying to do in my function is
public void DoSomething()
{
List<MyObjectA> ListA = new List<MyObjectA>();
List<MyObjectB> ListB = new List<MyObjectB>();
ListA = DAL.GetMyObjectAListFromDatabase();
I get an error in the line below for null exception in x.B_ID. If i debug through it. ListA has count > 0 and every x.B_ID has values . but the minute the below code is executed ListA becomes null not sure why.
I REPEAT THERE IS NO NULL IN THE ListA. WHEN THE FOREACH IS EXECUTED ListA BECOMES NULL. I WASDoing THIS TO REPLACE C# FOREACH. MY LIST IS CORRECT FOR FOREACH TO WORK. sO MY QUESTION WAS WHY THIS IS HAPPENING
ListA.ForEach(x => {
ListB.Add(new MyObjectB(x.B_ID));
});
}
All I am trying to do is looping through ListA to get B_ID and using B_ID to get ListB. As done in this linq. Linq style "For Each"
Please help me understand where I am going wrong