TAILIEUCHUNG - Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition phần 2

Phương pháp này đã được xác định để có một mảng tham số của tăng gấp đôi. Phương pháp này là trong thực tế, nói rằng, "Gửi cho tôi bất kỳ số lượng tăng gấp đôi và tôi sẽ tính toán mức trung bình." Vì điều này, bạn có thể gọi CalculateAverage () trong bất kỳ trong những cách sau đây | Simpo PDF Merge and Split Unregistered Version - http 112 CHAPTER 4 CORE C PROGRAMMING CONSTRUCTS PART II This method has been defined to take a parameter array of doubles. What this method is in fact saying is Send me any number of doubles and I ll compute the average. Given this you can call CalculateAverage in any of the following ways if you did not make use of the params modifier in the definition of CalculateAverage the first invocation of this method would result in a compiler error static void Main string args . _ Fun with Methods . Pass in a comma-delimited list of doubles. double average average CalculateAverage Average of data is 0 average .or pass an array of doubles. double data average CalculateAverage data Average of data is 0 average fir Average of 0 is 0 Average of data is 0 CalculateAverage Note To avoid any ambiguity C demands a method only support a single params argument which must be the final argument in the parameter list. As you might guess this technique is nothing more than a convenience for the caller given that the array is created by the CLR as necessary. By the time the array is within the scope of the method being called you are able to treat it as a full-blown .NET array that contains all the functionality of the base class library type. Figure 4-3 illustrates the output. Figure 4-3. The params keyword allows you to build methods with a variable number of arguments. Source Code The FunWithMethods application is located under the Chapter 4 subdirectory. Simpo PDF Merge and Split Unregistered Version - http CHAPTER 4 CORE C PROGRAMMING CONSTRUCTS PART II 113 Understanding Member Overloading Like other modern object-oriented languages C allows a method to be overloaded. Simply put when you define a set of identically named members that differ by the number or type of

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.