C # Advanced Programming Seventh Edition Learning Notes chapter II core C #

Source: Internet
Author: User

Chapter II Core C #

The contents of this chapter:

declaring variables

Initialization and scope of variables

Predefined data types for C #

Using conditional statements, loops, and jump statements to execute a flow in a C # program

Enumeration

Name space

Main () method

Basic command-line C # Compiler Options

Using System.Console to perform console I/O

Use internal annotation and documentation features

Preprocessor directives

Recommended rules and conventions for C # programming

2.1 First C # program

2.1.1 Code

Using System;

Namespace Wrox

{

public class Myfirstclass

{

static void Main ()

{

Console.WriteLine ("Hello from Wrox.");

Console.ReadLine ();

Return

}

}

}

2.1.2 Compiling and running the program

CS First.cs

First.exe

Hello from Wrox.

2.1.3 Detailed Introduction

The standard System namespace contains the most commonly used. NET types. All of the work done in C # is dependent on. NET base class.

2.2 Variables

Declaring variables in C # uses the following syntax:

datatype identifier;

Initialization of the 2.2.1 variable

C # has two methods to ensure that variables are initialized before they are used:

Variables are fields in a class or struct, and if they are not explicitly initialized, the default value is 0 when these variables are created

The local variables of the method must be explicitly initialized in the code before their values can be used in the statement. At this point, the initialization is not made when the variable is declared, but the compiler examines all possible paths through the method and generates an error if it detects that the local variable used its value before initialization.

2.2.2 Type inference

Type inference uses the VAR keyword to declare the syntax of a variable to be somewhat different. The compiler can "infer" the type of a variable based on the initialization value of the variable.

Some rules need to be followed:

Variables must be initialized. Otherwise, the compiler does not infer the basis of the variable type

The initializer cannot be empty

The initializer must be in an expression.

The initializer cannot be set to an object unless a new object is created in the initializer

Scope of the 2.2.3 variable 63rd page

2.3 Pre-defined data types

2.4 Flow control

2.5 Enumeration

2.6 Name Space

2.7 Main () method

2.8 More about compiling C # files

2.9 Console I/O

2.10 Using annotations

2.11 C # preprocessing directives

2.12 C # Programming rules

2.13 Summary

C # Advanced Programming Seventh Edition Learning Notes chapter II core C #

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.