Document directory
- 1st introduction to C # And. Net platforms
Part 2 Introduction to C # And. Net platforms Chapter 2. NET Path
From Chapter 2nd to Chapter 10th are the knowledge content of C # language. Assembly in chapter 1st is detailed in chapter 11th, and the basic language is a common intermediate language) the fourth part of the program is detailed in chapter 15th. This is my focus.
Page 9th: the last row: If ildasm.exe (described later) is used, the content in the brackets refers to section 4th of this chapter, on page 1.15 of this book.
The tool ildasm.exe is named msil disassembly program.
Chapter 2 build C # applications
This chapter does not provide C # language knowledge. It is a variety of tools for building C # applications. Reading this chapter reminds me of the Words Translated by Qiu zongyan In the translator's preface:A powerful program development environment may not be able to create better programmers
. One or two paragraphs in the translator's preface are excerpted below:
"In my own teaching practice, I met many students who were playing programming environment masters, but they were too far away from programming masters, they are not essential to algorithms and data structures, program architecture design, and various elements of good coding. They are most familiar with troubleshooting and single-step execution, and most well-known is program patching."
"A ten-line program can solve the problem. They need dozens or even hundreds of lines, but at last they do not know whether they are doing the right thing. They only know that they have tried some examples, there are countless patches in a single step. Sadly, it is not just these students who use this type of activity to compile, but not on campus or in China ."
I also remembered that when I was working in Bai Sheng, Shanghai, Lao Zhao used notepad to write C # programs very quickly to explain the implementation of an algorithm.
Chapter 2 C # language basics
Row 50th on page 2nd: the "Description" in "but to be introduced" should be "Description ".
3.1 A simple C # Program
All data members and methods in C # must be included in a category definition.
The project for creating a console application, named simplecsharpapp. The initial code statement may be as simple as you think:
using System;using System.Collections.Generic;using System.Text;namespace SimpleCSharpApp{ class Program { static void Main(string[] args) { } }}
Modify the code to the following code statement:
Using system; namespace simplecsharpapp {class program {static void main (string [] ARGs) {// display a simple message to the user console. writeline ("Hello world! "); // Wait for any key to close console. Readline ();}}}
Visual Studio defines the main () method in the "program" class by default. The class name ("program") can also be another name.
3.1.2 process command line parameters
In C #2008 and. Net 3.5 advanced programming (version 4th), the "..." following the main () method in the three sample codes in this Section are:
Console.ReadLine();return -1;
System. Console class
In this chapter, the second line: "Concepts observed" refers:C # syntax and core aspects of the. NET platform.
Use the console class for Basic Input and Output
The first sentence of the first section in this subchapter:The console class defines a set of methods for capturing input and output.
This "class" is type.They are all defined as static, so they can be called at the class level.
This "class" is a class. In my opinion, "calling from the class level" is based on C #2008 and. net 3.5 advanced programming (version 4th), the corresponding original sentence should be translated as: "using the class name console as the prefix to call the method name ".
The sample code for this chapter in version 4th is as follows:
Class program {static void main (string [] ARGs) {console. writeline ("****** basic console I/O *****"); getuserdata (); console. readline ();} static void getuserdata () {// obtain the name and age console. writeline ("Please enter your name:"); string username = console. readline (); console. writeline ("Please enter your age:"); string userage = console. readline (); // change the screen color, just for entertaining. consolecolor prevcolor = console. foregro Undcolor; console. foregroundcolor = consolecolor. Yellow; // console. writeline ("Hello {0 }! You are {1} years old. ", username, userage); // restore the previous color console. foregroundcolor = prevcolor ;}}3.3.1 role of Constructors
Programmers may forget to use functions such as Init () to initialize class objects, or do it twice (often with the same catastrophic consequences ). A better way is to enable the programmer to declare a function with the explicit purpose of completing object initialization, which constructs a value of a given type. It is called a constructor. For example:
class Date { //...Date(int,int, int);};
-- Excerpt from "C ++ programming language (Special Edition)" 10.2.3 Constructor (202nd pp. Of this book)
In the following code, the bold part is explicitly written into the default constructor:
using System;class HelloClass{ HelloClass() { } public static void Main(string[] args) { HelloClass c1 = new HelloClass(); }}Default Value of 3.6 class member variables
The default values automatically set for variables differ from those in C #2008 and. Net 3.5 advanced programming (version 4th:
From pm to PM, change to version 3rd:
- The char type is set to a single null character.
- The datetime type is set to 1/1/0001 12:00:00 AM.
- The object reference (including string) is set to null.
The following code is used to create a basic data type variable with the New Keyword C:
bool b = new bool();int i = new int();char c = new char();DateTime dt = new DateTime();Console.WriteLine("{0},{1},{2},{3}", b, c, i, dt);
In the "local variables" section on page 1, "simply make an initial value" differs from the corresponding part of the 62nd version:
You can declare and assign values in a single row, or you can divide the Declaration and value assignment statements into two lines of code:
// Datatype varname = initialvalue; int localint = 0; console. writeline (localint); // You can also divide the Declaration and value into two lines: String mystring; mystring = "this is my character data"; console. writeline ();
You can also declare multiple variables of the same type in a line of code:
bool b1 = true, b2 = false, b3 = b1;Console.WriteLine();
3.8 define constant data
In Figure 3-8, the constant used to view the const keyword is displayed. The following describes the variables used to remove the const Keyword:
. Field public static string bestnbateam
If you still have questions after reading the keyword readonly section, you can refer to the readonly code example in msdn:
public static readonly uint l1 = (uint)DateTime.Now.Ticks;
There will be a feeling of relief.
Comparison table of value type and reference type (see page 83rd)
| Question |
Value Type |
Cited type |
| Where is this type assigned? |
Allocated on Stack |
Allocated on managed stacks |
| How are variables represented? |
The value type variable is local replication. |
The reference type variable points to the memory occupied by the allocated instance. |
| What is the base type? |
Must inherit from system. valuetype |
It can inherit from any type except system. valuetype, as long as the type is not sealed's |
| Can this type be used as the base class of other types? |
No. The value type is sealed and cannot be inherited. |
Yes. If this type is not sealed, it can be used as a base class of other types. |
| What is the default parameter transfer? |
Variable is passed by value (that is, a copy of the variable is passed into the called function) |
Variables are passed by reference (for example, the address of the variable is passed into the called function) |
| Can this type rewrite system. Object. Finalize? |
No. The value type cannot be placed on the stack, so it does not need to be terminated. |
It can be overwritten indirectly. |
| Can I define constructors for this type? |
Yes, but the default constructor is retained (that is, the User-Defined constructor must have all parameters) |
Of course! |
| When will this type of variable die? |
When they get out of the defined scope. |
When the managed heap is reclaimed. |
For more information, see axman: Problem and Error List.