Illustration of the DOTNET Framework II: System

Source: Internet
Author: User

(Disclaimer: this series is intended for you only. the Net Framework is not an explanation of syntax and class usage. Therefore, you can only briefly describe the mentioned classes. If you have any questions, go to msdn to check)

 

We learned the. Net runtime engine and learned that the appdomain should carry various DLL, so let's take a look at the most basic system. dll.CodeBig guy to be referenced.
Still old rules, illustration...

After reading the figure, you should have a preliminary understanding. Let's study it one by one. Everyone knows. net is divided into value type and reference type, let's look at the difference between the two types

Object: this class is. net, which has some common methods, such as tostring, equals, and gethashcode. The template method (templete method) in gof23 is used here, in fact, we often use this mode during development, which saves the need for repeated classes to write these methods.
Valuetype :. all value types in. NET are derived from this class, but they are also derived from the object. It is strange that, in fact, only MS is used to make. net is completely object-oriented, and there is nothing to understand.

1. assignment Problem: The value type and reference type exist on the stack and stack respectively in the memory. When they assign values, the value type is replication, the reference type is itself (in fact, a new reference to the same object on the stack is generated ). it should be noted that the value type of the reference type is included, and the reference is also copied when the value is assigned. Do not confuse it.

Let's write some code to illustrate this problem.

Static   Void Main ( String [] ARGs)
{
Int I =   10 ;
Int J = I;
J =   20 ;
Console. Write (I ); /**/ ///The result I is still 10 but not 20 indicates that the assignment is copied.
Test T1 =   New Test ();
T1.age =   10 ;
T1.name =   " Test " ;
Test T2 =   New Test ();
T2 = T1;
T1.age =   20 ;
T1.name =   " Test2 " ;
Console. Write (t2.age. tostring () + " & " + T2.name ); /**/ ///The result is "20 & Test2", indicating that it is passed
}

2. Question about passing as a parameter: when passing a value as a parameter, if it is passed by value, it is copy. If it is passed by reference, it is itself. What about the reference type? Let's look at the code section:

Namespace Leleapplication3
{
Class Program
{
Class Test
{
Public StringName;//It is not encapsulated for convenience.
Public IntAge;
}
Static   Void Main ( String [] ARGs)
{


Test T1 =   New Test ();
T1.age =   10 ;
T1.name =   " Test " ;
Testmethod (T1 );
Console. Write (t1.age. tostring () +   " & "   + T1.name ); /**/ ///The result is "20 & Test2", indicating that the reference is passed, and the re-assignment of a reference will not affect itself.
Testmethod ( Ref T1 );
Console. Write ( " \ R \ n " + T1.age. tostring () +   " & "   + T1.name ); /**/ ///The result is "0 & null", indicating that it is passed.
Console. Read ();
}
Static   Void Testmethod (test T)
{
T. Age =   20 ;
T. Name =   " Test2 " ;
T =   New Test (); // Reinitialize here
}
Static   Void Testmethod ( Ref Test T) // Let's see what happens when passed by reference?
{
T. Age =   20 ;
T. Name =   " Test2 " ;
T =   New Test (); // Reinitialize here
}

Therefore, the reference type is passed according to the reference (REF. By passing the value, the reference type is passed.

Delegate: The base class of the Delegate. Pay attention to the delegate keyword. It inherits from multicastdelegate, and multicastdelegate inherits from delegate. the address list of the delegate type maintenance method is saved in the delegate object. this is. net delegate secret. here we use the proxy Design Pattern in gof23 to protect proxy.

 

 

 

The p r o x y mode is used to replace simple pointers with common and complex object pointers. The following are some common scenarios where the p r o x y mode can be used:
1) remote proxy provides a local representation of an object in different address spaces.

2) virtual proxy creates objects with high overhead as needed.
3) protection proxy controls access to the original object. Protection proxy is used when the object should have different access permissions.

4) Smart reference replaces simple pointers and performs some additional operations when accessing objects.

 

Here, delegate serves as realsubject, while multicastdelegate serves as proxy to protect some methods in delegate.

 

There are asynchronous calls to the delegate, which will be explained in the section system. threading.

 

Next article:. NET Framework and architecture mode and design mode series (Graphic DOTNET framework) II: system. Io

 

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.