This article aims to verify a confusing concept and pave the way for the transformation of INotifyProperty in WPF/Silverlight.
Two variables a and B of the same type have the following relationship:
B =;
If a changes, does B change?
The situation is very complicated. It can be discussed in the following situations:
1) single entity
1. Simple Type
First test int:
Int a = 1;
Int B =;
A = 2;
Console. WriteLine ("B:" + B );
Output result:
Check the string:
String a = "1 ";
String B =;
A = "2 ";
Console. WriteLine ("B:" + B );
Output result:
If you are not at ease, you can test the Enum. The result is similar. For details, see the Demo.
Conclusion: Simple type is the most basic unit for composite types. It is an atom and cannot be split. Therefore, no matter the value type is double, int, or reference type string, B does not change with, because they point to the same address on the global stack (for string, it is managed heap.
2. Composite Type
Composite types are simple types such as string, int, and double.
Define a composite reference type (class) and a composite value type (struct) respectively ).
Class UserInfo
{
Public string UserName;
Public int Age;
}
Struct UserInfo2
{
Public string UserName;
Public int Age;
}
First, we will discuss the reference type: