DEV Community

Discussion on: 5 C# Tips that you MUST know NOW!!! ⚡

Collapse
 
jayjeckel profile image
Jay Jeckel

It is great to see people writing about C#, but your article is missing crucial information.

Environment.FailFast() is for a very specific use-case and in general one should instead use Environment.Exit() to exit an application.

FailFast() is meant to be used when the process encounters a catastrophic error, such as one where external data could be destroyed. When the method is used, not only does it log an error with the OS, generate a memory dump, and try to send information to Microsoft, it also skips any active finally blocks and doesn't call any exit events. No one wants their application to panic, memory dump, and phone Microsoft every time it closes, so please use Exit() and not FailFast() to exit applications.

Also, it is great that you mentioned Environment.NewLine, but it is misleading to not explicitly point out that Environment.NewLine is a \n on Linux and \r\n on Windows as its purpose is to abstract over the OS differences of newline characters.