Wednesday, 27 April 2011

Class confusion - part 3

My problem with classes is I don't know how to make them return variables. If they can't return variables, then surely methods within the Program class are better? At least with them you can return a variable (even it's only just 1).

Also I keep getting errors about declaring classes. Let's take a look at that first.

After some work I've made this guide for myself, for creating classes:

static - whether the variables can be changed outside this method?
public - as above?
void / string / int - The variable type to be returned (void seems to be optional for the the first method in the class?
Method name - e.g. Main
(inputted variables) - e.g. (string variableName, int number)

This vaguely seems to be right so far. At first I thought static and public were mutually exclusive, but I found a class that had both.





The next problem is being able to use public variables. Can I use them outside of the class they're declared in? I would have thought so.

it seems to be classname.variablename
e.g. monster.health

Aha! I've finally got it working. Will post more later.

No comments:

Post a Comment