#C ා learning notes (1) — Preparation

Time:2020-11-14

1.1 download and install. Net framework

The. Net framework is a bit similar to Java’s JDK or Python parser, including compiler, execution engine, functional framework and some tools bundled with SDK. In summary, to compile and execute a C ා project, you need to install the. Net framework first.

It is recommended to download from the official website: https://dotnet.microsoft.com/…

#C ා learning notes (1) -- Preparation

The. Net core version is cross platform and can be used under windows, MacOS and Linux. The Framework version is only applicable to Windows platform. Generally, you can download “run apps” after you select build apps.

1.2 create source code

  • If you are using ide such as visual studio, select file new project, and select project C.
  • If you created it from the command line, you can enter the following code in turn:

    mkdir ./First 
    cd ./Fiest
    dotnet new console
    dotnet run

    Among them, “dotnet new console” is a newly generated program framework, which will generate a default program and contain some code, “dotnet run” is to compile and run the newly created project.

1.3 some basic names

using System;

namespace c_
{
    class Program
    {
        static void Main(string[] args)
        {
            int number; 
            Morning morning = new Morning;
            number = 1;
            //Print hi
            Console.WriteLine("Hi");
        }

    }
}
------
    class Morning
    {
        ...
    }
  • The name after using is called a namespace. Its function is to omit some of the names defined in the namespace. If you do not use the “using system” statement“ Console.WriteLine The sentence “Hi” should be written as“ System.Console.WriteLine (“Hi”);”。
  • Class is called a class, where the name of the class is “program.”.
  • Main is called a method. Methods are similar to functions in C language.
  • Args are called parameters. Parameters appear in parentheses after the method.
  • Int number is called the declaration of a variable. I want to create a variable called number, which is of type int. The so-called type is what the variable is, such as integers, characters, etc.
  • Number = 1 is called the assignment of a variable.
  • //When compiling, some comments on the hi side can be ignored.
  • The area enclosed by a pair of braces is called a scope. For example, the braces after main contain three lines of code, indicating that the scope of main is these three lines, and things beyond these three lines are “not in the same country” with main.
  • Morning morning = new morning statement is a new instance called morning (pay attention to case). The relationship between a class and an instance of a class is a bit like the relationship between a vase mold and a vase.
  • The code within the scope of a method is called method implementation, which refers to the specific content of the method.

1.4 simple naming suggestions

  • Class and method names. The first letter of each word is capitalized, such as HelloWorld.
  • The name of the variable is uppercase except the first letter of the first word, such as HelloWorld.
  • Although C ා is not mandatory, try to keep the class name consistent with the file name where the class is saved.
  • Try to use naming to indicate the necessary information instead of adding comments.

Recommended Today

Think about open source project promoting rust search extension: quickly search rust documents in the browser address bar

Open source project name:Rust Search Extension Introduction to open source projects:Quick search for rust documents in the browser address barOpen source project type:teamProject creation time:2020 GitHub data:375 Star,18 ForkGitHub address:https://github.com/huhu/rust-search-extension Rust search extension is a plug-in that can quickly search rust documents, Crites, built-in properties and error codes in the browser address bar. It supports […]