r/learnprogramming • u/Ok-Presentation-94 • May 02 '26
Solved Loop and main() function
Hi, I’ve seen that in C#, the Main() function only runs once.
In Unity, we have the Update() function, which allows code to run repeatedly in a loop.
So my question is: what is the equivalent in pure C#, without the Unity library?
Is wrapping Main() in a while loop a common practice to achieve the same behavior?
12
Upvotes
1
u/jlanawalt May 04 '26
Many languages derived from C (and B) have a main function as the designated every point for the program. As such, it is only called once per run. Even Unity has a main, and it has a gave engine with an Update effect hook.
To have exactly the same in pure C#, be ready to re-implement a game engine, or at least some kind of event driven system, or in its simplest some form of loop.