Addison Essential Csharp_2
Số trang: 98
Loại file: pdf
Dung lượng: 1.76 MB
Lượt xem: 5
Lượt tải: 0
Xem trước 10 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
về lập trình C # cho đến nay bạn sẽ có thể viết các chương trình đơn giản bao gồm một danh sách các báo cáo, tương tự như các chương trình được tạo ra vào những năm 1970. Lập trình đã đi một chặng đường dài từ những năm 1970, như các chương trình trở nên phức tạp hơn
Nội dung trích xuất từ tài liệu:
Addison Essential Csharp_2 4Methods and ParametersF about C# programming so far you ROM WHAT YOU HAVE LEARNED should be able to write straightforward programs consisting of a list ofstatements, similar to the way programs were created in the 1970s. Pro-gramming has come a long way since the 1970s; as programs became morecomplex, new paradigms were needed to manage that complexity. “Proce-dural” or “structured” programming provides a construct into whichstatements are grouped together to form a unit. Furthermore, with struc-tured programming, it is possible to pass data to a group of statements andthen have data returned once the statements have executed. This chapter covers how to group statements together into a method. Inaddition, it covers how to call a method, including how to pass data to amethod and receive data from a method. Namespace Type Name Exception Calling 6 1 Handling a Method Scope Method Name Parameters Method Return Method Declaring 5 2 Methods and Overloading a Method Parameters Value Parameters The Using 3 4 Parameters Directive Reference Parameters (ref) Aliasing Output Parameters (out) Parameter Arrays (params) Optional Parameters 149 From the Library of Wow! eBook150 C hapter 4: Methods and Parameters Besides the basics of calling and defining methods, this chapter also covers some slightly more advanced concepts—namely, recursion and method overloading, along with some new C# 4 features, namely optional and named parameters. All method calls discussed so far and through the end of this chapter are static (a concept which Chapter 5 explores in detail). Even as early as the HelloWorld program in Chapter 1, you learned how to define a method. In that example, you defined the Main() method. In this chapter, you will learn about method creation in more detail, including the special C# syntax for parameters that pass data to and from a method (ref) using a single parameter, as well as parameters that only pass data out from a method (out). Lastly, I will touch on some rudimen- tary error handling. Calling a Method BEGINNER TOPIC What Is a Method? Up to this point, all of the statements in the programs you have written have appeared together in one grouping called a Main() method. As pro- grams become even minimally larger, a single method implementation quickly becomes difficult to maintain and complex to read through and understand. A method is a means of grouping together a sequence of statements to perform a particular action or compute a particular result. This provides greater structure and organization for the statements that comprise a pro- gram. Consider, for example, a Main() method that counts the lines of source code in a directory. Instead of having one large Main() method, you can provide a shorter version that allows you to hone in on the details of each method implementation as necessary. Listing 4.1 shows an example. Listing 4.1: Grouping Statements into Methods class LineCount { static void Main() { int lineCount; string files; From the Library of Wow! eBook 151 C alling a Method D ...
Nội dung trích xuất từ tài liệu:
Addison Essential Csharp_2 4Methods and ParametersF about C# programming so far you ROM WHAT YOU HAVE LEARNED should be able to write straightforward programs consisting of a list ofstatements, similar to the way programs were created in the 1970s. Pro-gramming has come a long way since the 1970s; as programs became morecomplex, new paradigms were needed to manage that complexity. “Proce-dural” or “structured” programming provides a construct into whichstatements are grouped together to form a unit. Furthermore, with struc-tured programming, it is possible to pass data to a group of statements andthen have data returned once the statements have executed. This chapter covers how to group statements together into a method. Inaddition, it covers how to call a method, including how to pass data to amethod and receive data from a method. Namespace Type Name Exception Calling 6 1 Handling a Method Scope Method Name Parameters Method Return Method Declaring 5 2 Methods and Overloading a Method Parameters Value Parameters The Using 3 4 Parameters Directive Reference Parameters (ref) Aliasing Output Parameters (out) Parameter Arrays (params) Optional Parameters 149 From the Library of Wow! eBook150 C hapter 4: Methods and Parameters Besides the basics of calling and defining methods, this chapter also covers some slightly more advanced concepts—namely, recursion and method overloading, along with some new C# 4 features, namely optional and named parameters. All method calls discussed so far and through the end of this chapter are static (a concept which Chapter 5 explores in detail). Even as early as the HelloWorld program in Chapter 1, you learned how to define a method. In that example, you defined the Main() method. In this chapter, you will learn about method creation in more detail, including the special C# syntax for parameters that pass data to and from a method (ref) using a single parameter, as well as parameters that only pass data out from a method (out). Lastly, I will touch on some rudimen- tary error handling. Calling a Method BEGINNER TOPIC What Is a Method? Up to this point, all of the statements in the programs you have written have appeared together in one grouping called a Main() method. As pro- grams become even minimally larger, a single method implementation quickly becomes difficult to maintain and complex to read through and understand. A method is a means of grouping together a sequence of statements to perform a particular action or compute a particular result. This provides greater structure and organization for the statements that comprise a pro- gram. Consider, for example, a Main() method that counts the lines of source code in a directory. Instead of having one large Main() method, you can provide a shorter version that allows you to hone in on the details of each method implementation as necessary. Listing 4.1 shows an example. Listing 4.1: Grouping Statements into Methods class LineCount { static void Main() { int lineCount; string files; From the Library of Wow! eBook 151 C alling a Method D ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính tài liệu công nghệ thông tin lập trình máy tính mẹo máy tính cài đặt máy tínhGợi ý tài liệu liên quan:
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 317 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 305 0 0 -
Thêm chức năng hữu dụng cho menu chuột phải trên Windows
4 trang 290 0 0 -
70 trang 251 1 0
-
Bài giảng Tin học lớp 11 bài 1: Giới thiệu ngôn ngữ lập trình C#
15 trang 238 0 0 -
Tổng hợp lỗi Win 8 và cách sửa
3 trang 233 0 0 -
Sửa lỗi các chức năng quan trọng của Win với ReEnable 2.0 Portable Edition
5 trang 214 0 0 -
Giáo trình Bảo trì hệ thống và cài đặt phần mềm
68 trang 208 0 0 -
Tổng hợp 30 lỗi thương gặp cho những bạn mới sử dụng máy tính
9 trang 205 0 0 -
UltraISO chương trình ghi đĩa, tạo ổ đĩa ảo nhỏ gọn
10 trang 204 0 0