Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Sử dụng Namespaces Ví dụ bạn có thấy cho đến nay là một chương trình rất nhỏ. Tuy nhiên, các chương trình nhỏ sớm có thể phát triển thành các chương trình lớn hơn. Theo một chương trình phát triển, nó tạo ra hai vấn đề. Đầu tiên, thêm mã là khó hiểu và duy trì hơn so với mã ít hơn. | Using Namespaces The example you have seen so far is a very small program. However small programs can soon grow into bigger programs. As a program grows it creates two problems. First more code is harder to understand and maintain than less code. Second more code usually means more names more named data more named methods and more named classes. As the number of names increases so does the likelihood of the project build failing because two or more names clash especially when the program uses third-party libraries . In the past programmers tried to solve the name-clashing problem by prefixing names with some sort of qualifier or set of qualifiers . This solution is not a good one because it s not scalable names become longer and you spend less time writing software and more time typing there is a difference and reading and re-reading incomprehensibly long names. Namespaces help solve this problem by creating a named container for other identifiers such as classes. Two classes with the same name will not be confused with each other if they live in different namespaces. You can create a class named Greeting inside the namespace named TextHello like this namespace TextHello class Greeting . You can then refer to the Greeting class as TextHello.Greeting in your own programs. If someone else also creates a Greeting class in a different namespace and installs it on your computer your programs will still work as expected because they are using the TextHello.Greeting class. If you want to refer the new Greeting class you must specify that you want the class from the new namespace. It is good practice to define all your classes in namespaces and the Visual Studio 2005 environment follows this recommendation by using the name of your project as the toplevel namespace. The .NET Framework Software Developer Kit SDK also adheres to this recommendation every class in the .NET Framework lives inside a namespace. For example the Console class lives inside the System namespace. .