









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










contains the actual data of that type.Normally a value type contains a single pieceof information, such as an integer, a float, adouble, a bool, or a char.
if(Y>=0) return Y;else
return –Y;
} There is one parameter in the header. It’s name is Y.
To call the function MyAbs, there needs to be one
argument in the call. Z = MyAbs(Q);When this call is made, the
value
of Q is copied into
the value of Y, the parameter in the function. So, ineffect there are two variables, one in the callingprogram, and the other in MyAbs that contain thesame information.
Q is the argument in thecall.
static void Mystery(string Z){
do something with Z }
In the Main method consider:string Y;Y = “The moon is made of green cheese”;At this point Y contains an address, and that is
the address where the string is stored. Notethat the string is read only.
In the previous example, a reference type was
passed. It’s address was passed by value;hence, the string itself was passed byreference. The string still resides in only oneplace in memory. Its address is stored inboth Z and Y.
method parameter, changes to thatparameter inside the method, leave thecorresponding variable in the calling programunchanged.
Questions: 1.
What do you do if you want changes to aparameter in the method to result inchanges to the corresponding argument?
What do you do if you want a method tohave access to an argument’s data, but youdon’t want to pass the entire set of data?
static void MySwap(ref int A, ref int B)
int Temp = A;A = B;B = Temp;
} By placing the key word ref in front of the variable
declarations in the header, A and B will now“reference” the corresponding arguments in a call tothis function.
Integral: sbyte, byte char, short, ushort,intuint,long, and ulong.Floating: float and double.Others: decimal and bool Reference Types
string and object