Can you give me an infinite loop example on c# with minimum code? I came up with something but I thought there could be more easier way.
The typical examples are the for and while loops. For example
for(;;)
{}
and
while(true)
{}
However, basically any looping construct without a break or a terminating condition will loop infinitely. Different developers have different opinions on which style is best. Additionally, context may sway which method you choose.
while (true);
That should be enough.
The generated IL is:
IL_0000: br.s IL_0000
The code unconditionally transfers control to itself. A great way to waste CPU cycles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With