OK, I have come back. I have written so much in front, and I have had enough comparisons with JAVA. Now I will use my own example, let's take a look at the differences between C #, a new-generation programming language called JAVA # and JAVA.
First we create a C # program file cs1.cs, and then create a JAVA source program file cs1.java. Their content is:
Cs1.cs:
Using System;
Public class cs1 {
Public static void Main (){
Console. WriteLine ("I am sunwen! ");
Sunwen mySunwen = new sunwen ();
Console. WriteLine (mySunwen. name );
}
}
Class sunwen {
Public String name = "chenbin! ";
}
Cs1.java:
Import System .*;
Public class cs1 {
Public static void main (String args []) {
System. out. println ("I am sunwen, how are you! ");
Sunwen mySunwen = new sunwen ();
System. out. println (mySunwen. name );
}
}
Class sunwen {
String name = "chenbin! ";
}
OK. Let's run these two programs. during the compilation process, we found that C # is indeed much faster than JAVA. (not to mention M $) In fact, the output of the two programs is the same, both of which are:
I am sunwen!
Chenbin!
One important difference is that one row is publc String name = "chenbin! ", But in JAVA, It is String name =" chenbin! ". If we remove this public in cs1.cs, an error will be generated, because in C #, when no range modifier is needed, the default value is protect, therefore, it cannot be accessed outside the class.
This is one of the important differences. in addition, if we change the public class cs1 in the C # program cs1.cs to public class cs2, save the disk, and compile it, we can see that the program runs normally. in JAVA, this obviously does not work, because JAVA requires that only one public class can be contained in a file, and the name of this class must be the same as the file name. this is another difference. in C #, it uses the Main method to locate the entry. if a program does not have a method named "Main", an "portal error cannot be found" is returned ". don't write Main as main. I often make such errors.
Well, let's talk about it. Let's talk about it later!