+ 1
understanding the output on a question.
Why is the output "hisolo"? static void Main(string[] args) { new Super(); Console.WriteLine(); } class Super { static Super() { Console.Write("hi"); } public Super() { Console.Write("solo"); } }
4 odpowiedzi
+ 4
In practice I do not see static constructors being used often.
It is in the books because it can be used.
In this article below they show.
That all busses start with the same time.
To initialize the time they use a static constructor.
This is efficient.
Now all object use the same start time and this time is set only once at the beginning of the program.
Every object can make use of this variable which is part of the class not the object it self.
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors
Static -> part of class
non static -> bound to object
Start by using non static constructor, later. When you do more advanced programming you will know when you want to use a static constructor.
+ 1
because the code writes hi and then writes solo
0
slick ty for your response. I am trying to better understand why... Why not ignore one or the other?
I'm looking at this trying to better understand static vs nonstatic... Is there a scenario.. with modification. . one line would print out and not the other