How to play Beep sound through Console in C#?



To play beep sound through Console, the code is as follows −

Example

 Live Demo

using System;
public class Demo {
   public static void Main(String[] args){
      Console.WriteLine("Displaying standard output stream...");
      Console.WriteLine("Standard Output Stream = "+Console.Out);
      Console.WriteLine("Beep sound through Console");
      Console.Beep();
   }
}

Output

This will produce the following output −

Displaying standard output stream...
Standard Output Stream = System.IO.TextWriter+SyncTextWriter
Beep sound through Console

Example

Let us now see another example −

 Live Demo

using System;
public class Demo {
   public static void Main(String[] args){
      Console.WriteLine("Displaying standard output stream...");
      Console.WriteLine("Standard Output Stream = "+Console.Out);
      Console.WriteLine("Beep sound through Console");
      Console.Beep();
      Console.WriteLine("Beep sound through Console with frequence 1000 hertz and duration 500 milliseconds");
      Console.Beep(1000, 500);
   }
}

Output

This will produce the following output −

Displaying standard output stream...
Standard Output Stream = System.IO.TextWriter+SyncTextWriter
Beep sound through Console
Beep sound through Console with frequence 1000 hertz and duration 500 milliseconds

Advertisements