Go from CSharp to vb.net (i): MyClass reserved word

Source: Internet
Author: User
Reserved words in 2003 I contacted the first B/S project is dotnet, with the CSharp. Now 2 years later, also contacted VB.net project, step by step, see also the CLR platform, 2 languages on the reservation character is still very large.
Below I one by one columns come:
About MyClass, please first establish a vbconsoleapplication program, the article SOURCECP in

Module Module1

Class BaseClass
Public Overridable Sub MyMethod ()
Console.WriteLine ("Father is Years old!")
End Sub
Public Sub Useme ()
Me.mymethod () ' Use calling class ' version, even if a override.
End Sub
Public Sub Usemyclass ()
Myclass.mymethod () ' Use this version and ' override '.
End Sub
End Class
Class derivedclass:inherits BaseClass
Public Overrides Sub MyMethod ()
Console.WriteLine ("Child is just years old!")
End Sub
End Class


Sub Main ()
Dim Child as New derivedclass
Child. Useme ()
Child. Usemyclass ()
Console.ReadLine ()

End Sub

End Module
But in the CSharp cannot realize, C # How also does not allow me to call a virtual function in the form of a non-virtual function. C + + can access its own version of a function using the class Name:: Method Name, but C # 's class name can only be used to access static members. This is really a strange limitation of C #. Maybe it's my shaojianduoguai. This is described in MSDN:
MyClass behaves like an object variable referencing the current instance of the class when it was originally implemented. MyClass is similar to Me, but calls to all of its methods are treated as notoverridable by that method. Therefore, the method being invoked is not affected by overrides in the derived class. Although DerivedClass overrides MyMethod, the MyClass keyword in usemyclass invalidates the effect of the override, and the compiler resolves the call to the base class version of MyMethod.
MyClass cannot be used inside a shared method, but you can use it inside an instance method to access a shared member of a class.


But in the CSharp cannot realize, C # How also does not allow me to call a virtual function in the form of a non-virtual function. C + + can access its own version of a function using the class Name:: Method Name, but C # 's class name can only be used to access static members. This is really a strange limitation of C #. Maybe it's my shaojianduoguai. This is described in MSDN:
MyClass behaves like an object variable referencing the current instance of the class when it was originally implemented. MyClass is similar to Me, but calls to all of its methods are treated as notoverridable by that method. Therefore, the method being invoked is not affected by overrides in the derived class. Although DerivedClass overrides MyMethod, the MyClass keyword in usemyclass invalidates the effect of the override, and the compiler resolves the call to the base class version of MyMethod.
MyClass cannot be used inside a shared method, but you can use it inside an instance method to access a shared member of a class.
This is very good in business applications, such as the parent class is a employeebase, contains a basic salary of the data, then in the instantiation of employees, Dim E1 as New employee (EmployeeID), increase the staff's basic salary, in o/ When the R-image model is established, only the E1.addsalary (Salary) method can be invoked to invoke the base class's basic salary modification method. (That is, unified and basic salary). Personal opinion, hehe, the income is not good, also ask everybody to advise a lot.





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.