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
- Difference between Console.Write and Console.WriteLine in C#
- Difference between Console.Read and Console.ReadLine in C#
- Console Class in C#
- C# | How to change the CursorLeft of the Console
- Console.ReadLine() Method in C#
- Console.Clear Method in C#
- Console.SetWindowPosition() Method in C#
- Console.MoveBufferArea Method in C#
- Console.SetOut() Method in C#
- Console.SetIn() Method in C#
- Console.SetError() Method in C#
- Console.OpenStandardInput Method in C#
- Console.SetWindowSize() Method in C#
- Console.ResetColor() Method in C#
- Console.KeyAvailable() Property in C#
- Console.ReadKey() Method in C#
- Console.SetBufferSize() Method in C#
- Console.Read() Method in C#
- Console.SetCursorPosition() Method in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.