tailieunhanh - Writing Your First Program

Viết chương trình đầu tiên của bạn tập tin định nghĩa một lớp được gọi là Chương trình có chứa một phương pháp gọi là chính. Tất cả các phương pháp phải được định nghĩa bên trong một lớp học. Phương pháp chính là đặc biệt-nó chỉ định điểm vào của chương trình. Nó phải là một phương pháp tĩnh | Writing Your First Program The file defines a class called Program that contains a method called Main. All methods must be defined inside a class. The Main method is special it designates the program s entry point. It must be a static method. Methods are discussed in Chapter 3 Writing Methods and Applying Scope. Static methods are discussed in Chapter 7 Creating and Managing Classes and Objects. The Main method is discussed in Chapter 11 Understanding Parameter Arrays. IMPORTANT C is a case-sensitive language. You must spell Main with a capital M. In the following exercises you ll write the code to display the message Hello World in the console you ll build and run your Hello World console application you ll learn how namespaces are used to partition code elements. Write the code using IntelliSense technology 1. In the Code and Text Editor window displaying the file place the cursor in the Main method after the opening brace and type Console. As you type the letter C at the start of the word Console an IntelliSense list appears. This list contains all of the valid C keywords and data types that are valid in this context. You can either continue typing or scroll through the list and double-click the Console item with the mouse. Alternatively after you have typed Con the Intellisense list will automatically home in on the Console item and you can press the Tab Enter or Spacebar key to select it. Main should look like this static void Main string args Console NOTE Console is a built-in class that contains the methods for displaying messages on the screen and getting input from the keyboard. 2. Type a period immediately after Console. Another Intellisense list appears displaying the methods properties and fields of the Console class. 3. Scroll down through the list until WriteLine is selected and then press Enter. Alter-natively you can continue typing until WriteLine is selected and then press Enter. The IntelliSense list closes and the WriteLine

TÀI LIỆU MỚI ĐĂNG