- Home /
Refering to a Class without it initialization
Hello guys
I'm very sorry for that silly question but I seriously dont understand how it works in C#, but I realy like this feature to implement.
There are few freameworks like for example Facebook plugin or uLink server which allow you in any new script just write:
SomeClassName.SomeMethod(args);
without doing firts of all
SomeClassName myClass = new SomeClassName();
myClass.SomeMethod(args)
for example in Facebook plugin it starts directly from
FB.init()
or in uLink u can call
uLink.Login(args)
but where is initialization? where is Class myClass = new Class()? how do they start refering to "Class" it self without making it instance?
Could you please explain to me that? and sorry if my question sounds very silly
Answer by nikroth · Jan 10, 2014 at 03:23 PM
Classes without instances are the static classes. Example:
public static class MyClass()
{
public static void PrintHello() //method is static too
{
Debug.Log("Hello");
}
}
....
//using the class
MyClass.PrintHello(); //and it prints hello in the debug
oh I am so stupid, exactly all of the stuff in the FB.sc class from plugin in static, a part from class defenition it self, it is:
public sealed class - however as far as i know sealed means that this class cannob be inhirited, but doesn it automaticly makes it static?
Anyway thank you very much, was silly question, even if i dont have sources of uLink to check the way they implement classes I could sport it in FB plugin. Thank you very very much!
Over here I found good explanation:
http://stackoverflow.com/questions/16217313/static-vs-sealed-class-difference-dought
sealed class - doesnt mean static and more over can be instantiated, then why call FB.init() is allowed if class FB is not a static but sealed and could have several instances?
Your answer
Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Does Unity support application bootstrapping? 1 Answer
First time a method is executed is ~4 times slower 0 Answers