Assign the value of an object in another object
I have two classes class A and class B and a static list as show below
class A
{
int Id;
string firstName;
string lastName;
}
class B
{
int Id;
A a;
开发者_Go百科 string value;
}
class c
{
public static List<A> obj=new List<A>();
}
I need to assign the value of an item from the list 'obj' to the property a in an object of class B and not the reference of the item in the list.
The list 'obj' only contains references.
If you start cloning the instances of A (from the list to the 'B.a' property) you would have 2 instances with the same Id...
In other words your requirement is contradictionary with the fact that A has an ID (and thus a strong identity).
try like this
B b=new B();
C c=new C();
b.a.property= c.obj[i].property;
精彩评论