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.

The Console object has a Beep method which has a parameterless version:

Console.Beep();

It plays a short beep sound. If you’re not satisfied with it you can go for the overloaded Beep method that accepts a frequency in hertz and a duration in milliseconds. The lower the frequency value the deeper the sound:

Console.Beep(100, 5000);

That sounds like an organ.

Console.Beep(10000, 5000);

That on the other hand just sounds awful.

UPDATE: Saeid mentioned another way to produce sounds in console apps below in the comments section: the SystemSounds class.

View all various C# language feature related posts here.

Advertisement

About Andras Nemes
I'm a .NET/Java developer living and working in Stockholm, Sweden.

2 Responses to How to add basic sounds to a .NET console application

  1. Saeid says:

    Also it’s possible to call
    SystemSounds.Hand.Play();
    SystemSounds.Hand.Play();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Elliot Balynn's Blog

A directory of wonderful thoughts

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.

%d bloggers like this: