Home > Net >  A reference type and value type
A reference type and value type

Time:09-21

Ask bosses in c #
Judge Person p1=new Person (18) ∥ Person is a reference type Person p1 p2=
If p1 age=35
P2age is 35
A. to
Wrong B
Why choose to?
Thank you for your bosses

CodePudding user response:

Because the Person is a reference type, that is, the class
If it is a struct, so will not change,

CodePudding user response:

Because the Person is a reference type,
Person p2=p1,
Refer to the same address,

It is like a cup of milk tea, you insert 2 straw,
A straw one mouthful tea, B straws in the absorption, milk tea has A bit of inside



CodePudding user response:

refer to the second floor hanjun0612 response:
just because the Person is a reference type,
Person p2=p1,
Refer to the same address,

It is like a cup of milk tea, you insert 2 straw,
A straw one mouthful tea, B straws in the absorption, milk tea has A bit of inside

Thank you, that the same New person (18) what meaning be?

CodePudding user response:

reference m0_46188840 reply: 3/f
Quote: refer to the second floor hanjun0612 response:
just because the Person is a reference type,
Person p2=p1,
Refer to the same address,

It is like a cup of milk tea, you insert 2 straw,
A straw one mouthful tea, B straws in the absorption, milk tea has A bit of inside

Thank you, that the same New person (18) what meaning be?

The Person p1=new Person (18)
Is instantiated
Person p1 p2=
Is to put the p1 to p2, given a reference type, so this way of assignment, the public an address,

CodePudding user response:

reference 4 floor hanjun0612 response:
Quote: reference m0_46188840 reply: 3/f

Quote: refer to the second floor hanjun0612 response:
just because the Person is a reference type,
Person p2=p1,
Refer to the same address,

It is like a cup of milk tea, you insert 2 straw,
A straw one mouthful tea, B straws in the absorption, milk tea has A bit of inside

Thank you, that the same New person (18) what meaning be?

The Person p1=new Person (18)
Is instantiated
Person p1 p2=
Is to put the p1 to p2, given a reference type, so the way of assignment and public an address,

Uh huh, thank you for your bosses
  •  Tags:  
  • C#
  • Related