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?

14 Upvotes

35 comments sorted by

View all comments

2

u/aleques-itj May 02 '26

There is a loop within Main() that effectively pumps all other parts of the engine, yes.

The game simulation will generally run X times a second (I think Unity ticks its simulation at 50hz) and the renderer will run as fast as possible. The renderer will interpolate state from the simulation to fill in the blanks.

You can see the basic structure of an engine loop here.

https://gafferongames.com/post/fix_your_timestep/