Too bad you didn't include too much info on methods ....
like why are we writing static void or private void or private string etc ( although i hope you will get into the differences between static , public , private etc later on when you start to work with object etc.. )....
Therefore:
a method always has the following
an "access-identifier" ( don't know the correct word ) - a return type ( can be anything ranging from primitive types to objects to nothing -> void ) - name of the method - ( ) which can have from 0 upto as many paramaters as you like again the type being either primitive types or objects
A little bit more info on the parameters , they are being passed from where you call the method ( then these parameters are actually copied so you can use them in the scope of the method - meaning a parameter that is being changed inside that method will not effect the value of the argument that was originally passed )....
for instance
Code:
int i = 0;
this.Increment(i);
//i will not be incremented by one , the variable that is incremented is x , since i is copied into x when calling the method
....
public void Increment(int x) {
x++;
}
The only way to change a variable inside a function and still see the changes applied to the variable that was passed is if you use ref or out ( keywords ).
Use ref only when the passed variable is already initialized, out can be used if the variable is not yet initialized, for the rest they both do the same.
Usage of out and ref is being done like this
Code:
int i,x;
this.Increment(out i,outx);
//i and x will both be set to 1
....
public void Increment(out a, out b) {
a = 1;
b = 1;
}
....
int y = 1;
int z = 1;
this.Decrement(ref y,ref z);
// y and z will both be set to 0
public void Decrement(ref a,ref b) {
a--;
b--;
}
Of course there's alot more that can be said about methods. But I just wanted to add this since it sometimes can be usefull to pass multiple variables and make sure that the changes from inside a methode are being reflected to the passed arguments ( since you cannot return more then one variable in a method ) ...