Given a normal Console in C#, the task is to play a user modified Beep sound through the Console. User modified beep sound refers to the Beep sound played at a specific frequency for a specific duration of time.
Approach: This can be achieved with the help of Beep(Int32, Int32) method of Console Class in System package of C#.
The Beep(int, int) method of Console Class is used to play a Beep sound through the Console speaker at the specified frequency for a specified duration. These frequency and duration are specified as parameters to this method. By default, the beep plays at a frequency of 800 hertz for a duration of 200 milliseconds.
Syntax: public static void Beep (int frequency, int duration);
Parameters: This method accepts two parameters frequency and duration which are the frequency at which the Beep sound has to be played and the duration for which it is to be played, respectively.
Exceptions: This method throws following exceptions:
- ArgumentOutOfRangeException if the frequency is less than 37 or more than 32767 hertz if the duration is less than or equal to zero.
- HostProtectionException if this method was executed on a server, such as SQL Server, that does not permit access to a user interface.
Below programs show the use of Console.Beep(Int32, Int32) method:
Note: Please run the programs on offline Visual Studio to experience the output.
- C# | How to play Beep sound through Console
- Console Class in C#
- Console.KeyAvailable() Property in C#
- C# | How to change Title of the Console
- C# | How to change the WindowTop of the Console
- Console.ReadLine() Method in C#
- C# | How to change BufferHeight of the Console
- C# | How to change BufferWidth of the Console
- Console.SetBufferSize() Method in C#
- Console.ReadKey() Method in C#
- C# | How to change the WindowWidth of the Console
- C# | How to change the CursorSize of the Console
- Console.SetWindowSize() Method in C#
- C# | How to change the CursorTop of the Console
- C# | How to change the WindowLeft of the Console
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.