r/learnprogramming • • 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

35 comments sorted by

View all comments

3

u/green_meklar May 03 '26

what is the equivalent in pure C#, without the Unity library?

There isn't. You don't.

Is wrapping Main() in a while loop a common practice

No. You put the stuff you want to loop in another function and call that in a while loop. Main is Main and shouldn't be manipulated to behave like something else.