Đang chuẩn bị liên kết để tải về tài liệu:
Visual studio 2010 part 9
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Microsoft Visual Studio 2010: A của Hướng dẫn mới bắt đầu Chỉ cần gõ vào tên lớp trong lĩnh vực và nhấn ENTER. Các carat sẽ xác định vị trí vào bên trong các khối lớp. Bây giờ bạn biết làm thế nào để tạo ra các lớp học, bạn sẽ cần phải biết làm thế nào để thêm thành viên, bắt đầu với các phương pháp. | 72 Microsoft Visual Studio 2010 A Beginner s Guide Just type in the class name in the field and press enter. The carat will locate to the inside of the class block. Now that you know how to create classes you ll need to know how to add members starting with methods. Writing Methods You can divide your algorithms into blocks of code called methods. In different programming languages methods are called functions procedures or subroutines. I ll use the term method as a generic term except when I need to be more specific. You ve already used methods when coding Console.WriteLine where WriteLine is a method of the Console class. A method contains one or more statements. Reasons for creating methods include the ability to modularize your code isolate complex operations in one place or group a common operation that can be reused in multiple places. The following sections show you how to declare and use methods. Declaring and Using a Method To start off I ll show you a very simple method so that you can see the syntax and understand the program flow. Listing 3-5 will move the Console.Writeline statement from the Main method discussed in Chapter 2 into a new containing method and then add a statement to the Main method that calls the new method. Listing 3-5 Declaring and calling a method C Program.cs using System using System.Collections.Generic using System.Linq using System.Text namespace FirstProgram class Program static void Main string args MessagePrinter msgPrint new MessagePrinter msgPrint.PrintMessageInstance Chapter 3 Learning Just Enough C and VB.NET Types and Members 73 C MessagePrinter.cs using System using System.Collections.Generic using System.Linq using System.Text namespace FirstProgram class MessagePrinter public static void PrintMessageStatic Console.WriteLine Hello from a static method. public void PrintMessageInstance Console.WriteLine Hello from an instance method. VB Module1.vb Module Modulel Sub Main MessagePrinter.PrintMessageShared Dim msgPrint As