Defining Method under classes
[< modifiers >]void|type <name>([<param defn’s>]){
-stmts
}
- A method referred as a sub-program is a block of code that can be reused. We can categorize them into value returning and Non value returning methods.
- Modifiers - or some special keywords which can be used on a method like Public, Private, Virtual, Abstract etc.
- Void | type - we used void to a method to specify it was non- value returning where as if the method is value returning using the type we need to tell the type of value it was returning .
- Using the optional parameter “param defn’s” we can pass parameters to a method as following.
.----------------------------
A method can be defined with any number of parameters, where these parameters are divided into two types.
1. input parameters
2. Output Parameters.
- Input parameters are used for tacking a value into the method for execution, whereas output parameters are used for returning the value out of the method after execution.
- To tack input parameter we used pass by value” mechanism and for output parameter we used “pass by reference” mechanism, which is similar to pass by address in “C” language.
- To pass a parameter using pass by reference mechanism it should be prefixed with either “ref | out “keywords.
- [ = value ] - In C# 4.0 we are giving with a feature named and optional parameter, which allows defining a parameter with a default value while calling the method passing values to that parameter becomes optional.
0 Comments