I’ve just began using classes and would like to make some functions of a class visible outside that class. The problem is that I haven’t got (and unable to have) a variable of type Abc.
Let me explain with a snippet of code:
class Abc
{
private float foo;
public float Foo {
get { return foo; }
set { foo = value; }
}
public static void Hello() {
foo = 5.0f;
Console.WriteLine("Hello everyone!");
}
}
.... somewhere else ....
Abc bar;
bar.Foo = 5.0f; // ok, I know this
bar.Hello(); // fine, I know this too
Abc.Hello(); // I'm trying to do this!
EDIT:
Ok, now suppose I would like to assign something to foo in Hello (as in my code). I know this might sound like a nonsense, so I’m not sure it’s even possible.
You need a
staticmember function.staticmember functions are not associated with a particular instance of the class, which is what you will need if you want to access them via the class itself. The specifics vary slightly depending on whether you’re interested in C++ or C#.