Floating curly braces in C#

You can use an open and close set of curly braces to define a self containing block, which has its own scope.

This is generally not considered good programming practice, though.

Usually if someone is doing something like this, it's probably better to create a method/function in its place.


Any variable inside the "scope" of these curly braces will be out of scope outside of it.


It limits the scope of the variable to within that block. So the variable i would not be able to be seen outside of those braces.

It can also be a preference on if someone wants to separate code but using this when not necessary would in most cases be superfluous.

Tags:

C#