Java Programmer Learn C #

Source: Internet
Author: User

Because the work needs, I want to learn C #, in fact, I feel good, I like to learn more language, because this is very helpful to my future development, after all, the technology is not pressure, the following is my study today summarizes C # basic syntax:

I have learned C, but also Java programmers, so it is difficult for me to learn C #, here I integrated the basic C # syntax, as well as his and Java differences, but also for others want to learn C # 's partners to provide a convenient way, first of all to understand C # this language;

A simple description of C #: Microsoft Development language, similar to Java, syntax also has a lot of the same place, object-oriented programming language, and. NET has a relationship, the. NET Framework consists of a huge code base for client languages such as C #. We can use this development tool to develop C #:

    • Visual Studio (VS)

Let's start with a simple console application, the kind of small black box://When we create a project, the system automatically generates the Main method (the main entrance of the program), and introduces these seven bad characters, the introduction of files using using, The import is used in Java;

Using System.Collections.Generic;
UsingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;
This is a namespace, and when you create a project, the system automatically creates a project name for you. sln filenamespacefirstapp{
Here is the class name, and Java is different from the Java class name must be consistent with the file name, C # do notclassProgram {
The main function, which can also be called the Main method, is exactly the same as the Java definition. Static voidMain (string[] args) {
This is the output statement of C #, here with Console.WriteLine (); It's a bit like the System inside Java.out. println (); Console.WriteLine ("Hello world!");
This is the way C # defines variables, and Java is exactly the same, unlike in C # can use Var to define variables, which is a bit like JS, you can let the system itself to determine what type of variable, but pay attention to the variables defined by VAR must be assigned the initial value;intx = the; Console.WriteLine (x); intz =Ten; Doubley = -;
Output the variable Console.WriteLine in the form of a placeholder ("x = {0}; y = {1}", z, y); stringYourName;
       
Console.WriteLine ("What is your name?"); /* This is the statement that gets the user input in C #, using Console.ReadLine ();
Similar to Java in Scanner Scanner = new Scanner (System. in); int i = Scanner.nextint ();
The difference is that C # can directly call the ReadLine () in the console to get input, whereas in Java it is necessary to instantiate the scanner and then adjust the Nextint () method, and receive the different methods depending on the type of input content.
C # does not need to be so troublesome, just readline to accept all types, and if you want to accept only certain types of values, you can convert the input using the following method.
YourName=Console.ReadLine (); Console.WriteLine ("Hello {0}", YourName); Here, using the Convert.ToInt32 () method, the input is converted to int, and if the input content cannot be converted to int, the error will be made;intAge =Convert.ToInt32 (Console.ReadLine ()); Console.WriteLine ("You is {0} years old", age);
Here is the method to define the solid, solid is not can be assigned the second time, once the assignment can not be changed, here in front of the variable with the Const keyword can be, in Java need to add the final keywordConst DoublePI =3.14; Console.WriteLine (PI);
To prevent the small black box after the second back, so it is equivalent to do a user input enter key to intercept Console.readkey (); } }}

These are the basic C # syntax, other object-oriented features I will not say, like encapsulation, inheritance, polymorphism. There are some, like interfaces, exception handling, file streams, events, collections, generics, threads these things are the same logically, there is nothing to say, if not, you can look at my blog home page related to the Java processing methods, appropriate change of syntax, it can be.

Java Programmer Learn C #

Related Article

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.