Analysis of N cases of B = a in C #

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.