开发者

Assign the value of an object in another object

开发者 https://www.devze.com 2023-02-28 00:52 出处:网络
I have two classes class A and class B and a static list as show below class A { int Id; string firstName;

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;

0

精彩评论

暂无评论...
验证码 换一张
取 消