c# exit program

C#
if (System.Windows.Forms.Application.MessageLoop) 
{
    // WinForms app
    System.Windows.Forms.Application.Exit();
}
else
{
    // Console app
    System.Environment.Exit(1);
}System.Windows.Forms.Application.ExitThread( )System.Environment.Exit(1);Application.Exit();
Source

Also in C#: