Chapter 4. Methods and Parameters
From what you have learned about C# programming so far, you should be able to write structured programs that are similar to programs created in the 1970s. Obviously, programming has come a long way since the...
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 programs become even minimally larger, a single me...
Declaring a Method
This section expands on the explanation of declaring a method (such as Main()) to include any parameter or a return type. Listing 4.4 contains examples of these concepts, and Output 4.1 shows the results.
Listing 4.4. Declaring...
The using Directive
It is possible to import types from one namespace into the enclosing namespace scope. As a result, it would not be necessary for the programmer to fully qualify a type. To achieve this, the C# programmer includes a using direct...
Returns and Parameters on Main()
So far, declaration of an executable's Main() method has been the simplest declaration possible. You have not included any parameters or return types in your Main() method declarations. However, C# supports the abi...
Parameters
So far, this chapter's examples have returned data via the method return. This section demonstrates the options of returning data via method parameters and via a variable number of parameters.
Beginner Topic: Matching Caller Vari...
Recursion
Calling a method recursively or implementing the method using recursion refers to the fact that the method calls back on itself. This is sometimes the simplest way to implement a method. Listing 4.15 counts the lines of all the C# source...
Method Overloading
Listing 4.15 called DirectoryCountLines(), which counted the lines of *.cs files. However, if you want to count code in *.h/*.cpp files or in *.vb files, DirectoryCountLines() will not work. Instead, you need a method that takes...
Basic Error Handling with Exceptions
An important aspect of calling methods relates to error handling; specifically, how to report an error back to the caller. This section examines how to handle error reporting via a mechanism known as exception ...
Summary
This chapter discussed the details of declaring and calling methods. In many ways, this construct is identical to its declaration in C-like languages. However, the addition of the keywords out and ref are more like COM (the predecessor to ...
AJAX popular information C# language guides Windows books and cookbooks
.......
С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.