How to redirect standard input for a .NET console application

Normally .NET console applications read their input from the console through Console.ReadLine(). The user is prompted for some input, they enter some text, press enter and the console can read this input.

However, this is not the only option you have. The standard input channel can be overridden.

Read more of this post

How to hide the key pressed in a .NET console application

You probably know how to read the key pressed by the user in a .NET console application by the Console.ReadKey() method:

ConsoleKeyInfo pressedKey = Console.ReadKey();
Console.WriteLine("You have pressed: {0}", pressedKey.Key);

Read more of this post

Introducing the Command Line Parser Library to make parsing command line arguments easier

If you’ve worked extensively with .NET console applications then you’ve probably encountered difficulties with parsing the command line arguments. They are passed into the args argument of the Main function. Then it’s your task to investigate if the caller has passed in all necessary arguments:

  • Have all the mandatory arguments been passed in?
  • What default value do we take for optional arguments?
  • What about the ordering of arguments?

…et cetera, the list could grow a lot longer.

Fortunately there are libraries that can help you parse the arguments. One such library is called Command Line Parser Library available from NuGet here. You can find its project page here with some initial code examples.

Read more of this post

How to change the size of the command prompt in a .NET console application

Occasionally you might need to change the size of the console window in a .NET console application. There are methods and properties available in the Console object that enable you to perform this operation easily.

Read more of this post

Extract the full argument list as a string in a .NET console application

You probably know that arguments to a .NET console application are passed in as a string array through the Main function.

The command…

myapp hello goodbye

…will populate the args argument…

static void Main(string[] args)

…with two string elements: “hello” and “goodbye”.

If you ever need to look at the full command including the name of the executable and the command line arguments then the Environment.CommandLine property can help you:

Read more of this post

How to change the colours in a .NET console application

Sometimes you need to change the fore- and background colours in your .NET console application. Normally it’s fine with the traditional black background and white foreground colours – or whatever the user has set as default colours – however, some message types may deserve extra attention.

This short post will demonstrate how to change the colours in a console application.

Read more of this post

How to terminate a .NET console application with an exit code

It happens that you’d like to terminate a .NET console application with some exit code. Normally exit codes are integers where negative numbers indicate that something has gone wrong with -1 being the most common. Positive digits and zero on the other hand usually imply a program execution with no errors. The most common positive exit codes are 0 and 1.

Read more of this post

How to add basic sounds to a .NET console application

We all know a couple of very annoying features of web sites: popups, flashing text, rotating images and the like. The good news is that there are some equally annoying features that you can add to .NET console applications: constantly changing titles, console window size and position, text size and colour etc.

In this short post we’ll see how to add a basic beep to a console app. As with the above mentioned features you should not overuse it.

Read more of this post

How to hide the text entered in a .NET console application

You’ve probably encountered console applications that ask for a password. It’s very likely that the password will stay hidden otherwise other people viewing your screen can easily read it.

This short post will present a possible solution on how to achieve a hidden string input in a .NET console application.

Read more of this post

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

HarsH ReaLiTy

A Good Blog is Hard to Find

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: