In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the details of the comparison between C# and VB7". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the details of the comparison between C# and VB7.
Variable declaration
The variables of C # and VB7 are basically the same. Unlike VB6, VB7 can assign initial values while declaring variables, instead of declaring Dim x as an undetermined type, VB7's integer (Integer) variable is 4 bytes (32-bit integer,-2147483648), and the long integer (Long) is 8 bytes (64-bit integer,-9223372036854775808color 9223372036854775807).
Second, the call of net class function library.
Both C # and VB7 call the same .NET class library, so the instructions for C # and VB7 programs to call .NET class libraries are exactly the same.
The following example defines the method input () to input a long integer m from the keyboard, and the method CalcSqrt (mm As Long) to calculate and display the square root of m; it uses the input and output method of the console class Console of System in the .NET class function library and the (square root) method Sqrt; of the mathematical calculation class Math. In addition, the Int64-like method FromString (cc) is used to convert the numeric string cc into a long integer.
The running result of the program (assuming that the input is 999, note that the return value of the mathematical function is generally double precision)
Type a positive integer:
Calculation result: Sqrt (999) = 31.606961258558215
It is easy to see that this C # program is almost exactly the same as the VB7 program. If you write a VB7 program, you can easily change it into a C # program; it is the essence of Microsoft .NET to unify the programming (in different languages) into the .NET class library.
III. Object-oriented programming
In the above example, the method input () is defined to input a long integer m from the keyboard, and the method CalcSqrt (mm As Long) calculates and displays the square root of m, and then calls it in the Main () method. Here, separate the method input () from the method CalcSqrt (mm As Long) into a special class (LY0), and then generate an instance object for use in the Main () method of class LY:
The running result of the program is still exactly the same as that of (2).
In the case of object-oriented, this C # is almost exactly the same as the VB7 program. In this sense, it can be said that VB7 is Che Zhen C #, that is, VB7.
VB7 routine (03_vb.vb):
Imports System Class LY0 / / comment: variables m and Q are now encapsulated in class LY0 and protected because another class, LY, refers to m Add public Public Dim m As Long Dim q As Double / / comment to m: enter a long integer m Public Sub input () Console.Write ("Please type a positive integer:") Dim cc As string=Console.ReadLine () comment: get the numeric string m=Int64.FromString (cc) entered by the keyboard comment: convert this string to a 64-bit integer m End Sub / / comment: calculate and display the flat of the mm Square root Public Sub CalcSqrt (mm As Long) q=Math.Sqrt (mm) Note: the mathematical function Sqrt is in the class Math of System Return Double. Single Console.Write is not available ("calculation result: Sqrt () =", mline Q) Note: display result End Sub End Class Public Module LY Sub Main () Dim obj As LY0 = new LY0 () obj.input obj.CalcSqrt (obj.m) End Sub End Module
The 02_c#.cs of C # is almost exactly the same as the VB7 routine:
The using System; class LY0 {/ / variables m and Q are now encapsulated in class LY0 to be protected, because the other class LY refers to m, public public long m; double q; / / enter a long integer m public void input () {Console.Write ("Please type a positive integer:"); string cc = Console.ReadLine (); / / get the numeric string m=Int64.FromString (cc) entered by the keyboard / / convert this string to a 64-bit integer m} / / calculate and display the square root of mm q public void CalcSqrt (long mm) {q=Math.Sqrt (mm); / / Mathematical function Sqrt returns Double in the class Math of System, but Single Console.Write is not available ("calculation result: Sqrt () =", mForce Q); / / display result} class LY {static void Main () {LY0 obj = new LY0 (); obj.input () Obj.CalcSqrt (obj.m);}} at this point, I believe you have a deeper understanding of "the details of the comparison between C# and VB7". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.