Showing posts with label Console. Show all posts
Showing posts with label Console. Show all posts

Instead of displaying x item(s) found

from today on we use the following code

Console.WriteLine("{0} item{1} found.", count, count==1 ? "" : "s");

and get a nice output like

201 items found 

instead of

201 item(s) found 

 

From stackoverflow
http://stackoverflow.com/questions/9033/hidden-features-of-c/821718#821718

Application.Exit vs. Environment.Exit

I looked over my sources and saw that i used Application.Exit and sometimes Environment.Exit... Without ever knowing, when exactly to use the right procedure!

This article gave me clearness
Application.Exit vs. Environment.Exit

Msdn Help
Application.Exit
Environment.Exit

Essence of the blog post!

if (System.Windows.Forms.Application.MessageLoop)
{
   // Use this since we are a WinForms app
   System.Windows.Forms.Application.Exit();
}
else
{
   // Use this since we are a console app
   System.Environment.Exit(1);
}
Good example - Code determines in which context used, Console, Winforms, Class Library, and calls right method

Latest Posts

Popular Posts