tailieunhanh - C 2.0 practical guide for programmers PHẦN 6

Trong trường hợp của sự trở lại không khoảng trống, các loại giá trị expr tương thích với kiểu trả về theo quy định của phương pháp. Ví dụ, nếu là trở lại thay vì 1 trong ví dụ trước, sau đó là một lỗi biên dịch được tạo ra. Vì vậy, các phương pháp tĩnh được sử dụng để chuyển đổi các args string | 116 Chapter 6 Statements and Exceptions else return 1 public static void Main string args if 0 Usage Factorial n return main is a void method that can use return. int n args 0 n Process n In the case of the non-void return the type of the Expr value must be compatible with the return type specified by the method. For example if is returned instead of 1 in the previous example then a compilation error is generated. Therefore the static method is used to convert the string args 0 to its integer equivalent. checked unchecked Statements The checked and unchecked statements control the context of overflow checking for integral-type arithmetic operations and conversions. These statements were covered in Chapter 5. lock and using Statements The lock statement delimits an embedded statement as a mutually exclusive critical I EBNF I section for an object represented by the expression Expr. LockStmt lock Expr EmbeddedStmt . Because no implicit boxing is performed on Expr the expression must be a reference type. Otherwise a compile-time error is generated. The lock mechanism itself is implemented with a monitor synchronization primitive generated by the C compiler that ensures that only one thread at a time is exclusively active in a critical section. The using statement in C acquires one or more resources executes a statement and I EBNF I then disposes of the resource s . UsingStmt using ResourceAcquisition EmbeddedStmt . ResourceAcquisition LocalVarDecl Expr . Both the lock and using statements are covered in greater detail in Chapter 9 in the context of threads and input output respectively. Exceptions and Exception Handling 117 Exceptions and Exception Handling Software developers have long realized that moving from a procedural to an object-oriented approach requires a completely different mindset. Similarly using exceptions as opposed to the traditional approach of returning

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG