First off tip of the hat to Tamer Maher:
Cy Khormaee and Bradley Jensen who will be joining their student teams to attend the Imagine Cup in Cairo, Egypt! They will be joining my other teammates: Dan Waters, Clint Rutkas, and Diane Curtis.
In the previous blog I said that we would go over how to use abstract classes. I decided to discuss object instantiation from classes
Now back to something that is entirely on track to using existing code and building code that you can share with others.
A few important points:
Objects can be created using the new keyword followed by the name of the class that the object will be based upon.
In C# you create the object from the class pattern by the code, written here where the object is given the same name as the class, in the following line of code, I show you the way that is more professional and easier to utilize:
Avatar Avatar = new Avatar(); //Can be confusing, but used in many examples
A better way to instantiate an object would be to give the instantiated object a separate but clear name:
Avatar BaldGuy = new Avatar(); //Less confusing and more descriptive
When an instance of a class is created (instantiate), a reference to the object is passed back to the programmer (the yellow arrow in the figure). In the example above, BaldGuy is a reference to an object based on Avatar. This reference refers to the new object, but does not contain the object data itself. In fact, you can create an object reference without creating an object at all:
Creating object references that do not reference an object is a bad idea because it will fail at run time which occurs after you compile the program. This is an error that will not show up until you try to use your program.
However, such a reference can be made to refer to an object, either by creating a new object, or by assigning it to an existing object, like this:
Avatar BaldGuyB = new Avatar();
Avatar BaldGuyC = BaldGuyB;
This is very good news was well informed that the followers of the issue I am. Thanks...