tailieunhanh - aspnet sample_part6

Chương 3: Khái niệm cơ bản Lập trình và C # File: 'Đây là chức năng getName Chức năng của chúng tôi () Quay trở lại chuỗi "Zak Ruvalcaba" End Function' Và bây giờ chúng tôi sẽ sử dụng nó trong Page_Load xử lý Sub Page_Load (Như Object, e Như EventArgs) = getName () End Sub C # File: | Chapter 3 and C Programming Basics File html head script runat server language VB Here s our function Function getName as String Return Zak Ruvalcaba End Function And now we ll use it in the Page_Load handler Sub Page_Load s As Object e As EventArgs getName End Sub script head body form runat server asp Label id lblMessage runat server form body html C File html head script runat server language C Here s our function string getName return Zak Ruvalcaba And now we ll use it in the Page_Load handler void Page_Load getName script head body form runat server asp Label id lblMessage runat server form 60 This iShetrialonVersion ll 700 pages Functions body html Figure shows the result in the browser. Figure . The Page_Load event is raised the function is called and the code within the function is executed. Here s what s happening the line in our Page_Load subroutine calls our function which returns a simple string that we can then assign to our label. I hope this illustrates what functions are about and how you can use them. In this simple example we re merely returning a fixed string my name but the function could just as well retrieve the name from a database or somewhere else. The point is that regardless of how the function gets its data we use it that is call it in just the same way. Order the prin .5 er is -hiis trial version 61 Chapter 3 and C Programming Basics When we re declaring our function we must remember to specify the correct return type. Take a look at the following code Here s our function Function addUp x As Integer y As Integer As Integer Return x y End Function And now we use it in Page_Load Sub Page_Load s As Object e As EventArgs addUp 5 5 .ToString End Sub C Here s our function int addUp int x int y return x y And now we use it in Page_Load void Page_Load addUp 5 5 You .

TỪ KHÓA LIÊN QUAN