Sunwen Tutorials----C # advanced (11)

Source: Internet
Author: User
First we build a C # program file Cs1.cs, and then build 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 is you!");
Sunwen mysunwen=new Sunwen ();
System.out.println (Mysunwen.name);
}
}

Class sunwen{
String name= "chenbin!";
}


OK, let's run the two programs. In the process of compiling, we find that C # is actually much faster than Java. (not to say m$) in fact, the output of the two programs is the same:

I am sunwen!
chenbin!

One important difference is that there is a line of PUBLC string name= "chenbin!", while in Java it is a string name= "chenbin!". If we remove this public from the Cs1.cs, it will produce an error, because in C #, without any scope modifier, the default is protect and cannot be accessed outside the class.

This is one of the important distinctions. There is also: if we cs1.cs this C # program in a public class CS1 to public class CS2, save, and then compile, you can see, the program runs normally. In Java, this is obviously not possible because Java rules , there can be only one public class in a file, and the name of the class must be exactly the same as the file name. This is another difference, in C #, it is the main method to locate the entry. If there is not a method named Main in a program, there will be "No entry errors found". Don't write main to the main yo, hehe, I often make such mistakes.

The above is the Sunwen tutorial----C # Advanced (11) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.