Original Post
Ok, We're really starting to get somewhere. Chapter 11 with the new week beginning. So, I guess it would be a good time for me to take a look at how I am looking at code and let people start straightening me out before I get too deep and off the beaten path of righteous understanding. I placed comments of what I think is going on at each step. Please correct me and/or add opinions on what I should be noticing. Thanks in advance. [Edited by - JWalsh on July 30, 2007 9:44:18 AM]
//Use classes from the System Namespace
using System;
//Define a class
class PassArrayByValue
{
//Create the starting point of not only this class but of the program itself
static void Main()
{
//Allocate an area of memory for an array of type int
//At the same time, this allocated memory will be sized to hold 10 int //+objects
int[] arr = new int[10];
//Assign a value of 22 to the index of Zero/first pos. of the array
arr[0] = 22;
//Now pass the reference of the array object to the AlterInteger Method
//This is the address to its location in memory
AlterInteger(arr);
//Write out to the console the value at index 0/First index
Console.WriteLine(arr[0]);
//Used this to pause the dos window so it wouldn't close on me
//for reading purposes
Console.Read();
}
//A method that won't return a value
//This method will only accept array objects of type int
static void AlterInteger(int[] arr)
{
//Index 0/first position of the array is now being assigned a value of //55
arr[0] = 55;
//Since this is an object reference, the array object itself will actually be modified to this value.
}
}