Sunday, 1 May 2011

Class clarity

I have my classes working now, since I've figured out the code (see below). I'm still not sure about the meanings of 'public' and 'static'. At first I thought they were mutually exclusive, but I was wrong. You have can have a method which is both public and static, which implies they refer to something different.


Making a new object
ClassName object1 = new ClassName();


Running a method for a particular object
MethodName(object1);
or
ClassName.MethodName(object1);


A method that takes an object for input
static void MethodName(ClassName ClassName)
        {
        }


Refering to an object's variable
object1.variableName

e.g.
Console.WriteLine(object1.variableName);
or
object1.variableName = 6


A new class
class Monster
    {
        public int variableName;
    }


A new method within that class
public static void MethodName(ClassName ClassName)
    {
    }

No comments:

Post a Comment