SUNWEN tutorial - C# advanced (11)

黄舟
Release: 2016-12-19 10:27:48
Original
1031 people have browsed it

First we create a C# program file cs1.cs, and then create a JAVA source program file cs1.java. Their contents are:

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. (I’m not saying good things about M$) In fact, the output of the two programs is the same , both are:

i am sunwen!
chenbin!

An important difference is that there is a line that says public String name="chenbin!", but in JAVA it is String name="chenbin!". If If we remove this public in cs1.cs, an error will occur, because in C#, when no scope modifier is used, the default is protect, so it cannot be accessed outside the class.

This is an important difference 1. Another thing is: if we change the sentence public class cs1 in the C# program cs1.cs to public class cs2, save it, and compile it again, you can see that the program runs normally. In JAVA, this obviously does not work, because JAVA stipulates that there can only be one public class in a file, and the name of this class must be exactly the same as the file name. This is another difference. In C#, it uses the Main method to locate the entry. If there is no A method named Main will cause an "entrance not found error". Don't write Main as main, hehe, I often make such mistakes.

The above is the SUNWEN tutorial - C# Advanced (11) content, please pay attention to the PHP Chinese website (www.php.cn) for more related content!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!