: Thanks for your insight. Seems you went the path I have been
: thinking of... I have C# Express as well as VS2008. Syntax is
: syntax. I don't have much a problem with that. The USING
: statements vs. Unit includes - there should be a reference to assist
: with that learning curve.
Help Files. But seriously, it's more of a repetitive learning game I think.
: Another question? I am having a logic problem, though. Is there a
: reference that can clarify/compare the differences between
: procedures and functions with the vernacular of classes and uses of
: public, global, etc?
Hmmm. Vernacular? Had to look that one up, it's not in my standard word use. lol. Still not totally sure of the definition although I read Webster's definition.
Anyways, not sure where you are lost as to Procedures/Functions. Pascal had Procedures, which could take input vales, but returned noting, and it had Functions that could take input values and would return something. C# on the other hand doesn't use name declarations such as PROCEDURE/FUNCTION, instead it just figures it out by what is returned.
A procedure is declared like so:
void printResults( string textToShow )
{
MessageBox.Show(textToShow);
// Doesn't need to be here, but if needed in a procedure can be called.
// Notice there is no value passed to return as the procedure returns no value (VOID).
return;
}
The same function would be declared like so:
int printResults( string textToShow )
{
MessageBox.Show(textToShow);
// A function must call return.
// Notice the value passed to return
return 26;
}
I don't think GLOBAL even exists, but because everthing is in a class in C#, everything must be public or private (if undeclared it has set defaults)
Any Procedures/Functions in the class have access to all variables and other functions in that class, but if a second class wants to access either a function or a variable in the first class, they must be declared as public.
Also, they can be declared static as well, which means that variable/function will be the same no matter how many of those classes are created. I am still new to C#, so writing code from head isn't good. Here's the basic concept though:
class myHockeyGame
{
class playerInfo
{
public int number;
public string name;
// speed is a private variable so others can't change it
private int speed;
// Constructor allows speed to be set when player created
void playerInfo(int setSpeed)
{
speed = setSpeed;
}
public int getSpeed()
{
return speed;
}
}
class teamInfo
{
public string name;
public static string homeTown;
public playerInfo[] players;
}
// Create a team
teamInfo myTeam = new teamInfo();
myTeam.name = "Canucks";
myTeam.homeTown = "Vancouver";
// Create a player
playerInfo myPlayer = new playerInfo(80);
myPlayer.number = 1;
myPlayer.name = "Roberto";
playerInfo[] myTeam.playerInfo = new playerInfo[1];
myTeam.playerInfo[0] = myPlayer;
// Create a second team
teamInfo myTeam2 = new teamInfo();
myTeam2.name = "Kings";
myTeam2.homeTown = "L.A.";
}
This all looks okay (other than mistakes), except because we declared
homeTown as static, myTeam.homeTown will now be "L.A." and not "Vancouver".
Obviously you wouldn't use it in a situation like this, but there are times when you need a class to have a sort of "global" variable.
Hope this helps a bit. If I'm way off, just give me a slap.