In C#, Console.Beep asks the system to play a short alert sound. The parameterless call uses a default beep.
An overload accepts frequency (Hz) and duration (milliseconds). Support varies by platform—some environments ignore Beep or only allow the default sound. Treat it as a nice-to-have signal, not a guaranteed audio API.
This is a static member of System.Console. You call it with the type name, such as Console.Beep(...). Console is the everyday API for reading from standard input and writing to standard output in C# console apps.
Syntax
Call Beep() or Beep(frequency, duration) on supported systems.
C#
Console.Beep();
Console.Beep(800, 200);
Call
What it does
Console.Beep()
Default system beep.
Console.Beep(800, 200)
About 800 Hz for 200 ms when supported.
Beep may be platform-limited or silent. Do not rely on it for critical feedback alone.
Library declarations
C#
public static void Beep();
public static void Beep(int frequency, int duration);
Parameters
Parameter
Description
frequency
Optional. Pitch in hertz (typical useful range roughly 37–32767 on Windows).
duration
Optional. Length in milliseconds.
Return Value
Return Value
Description
void
Nothing is returned; a sound may play.
C# Examples
Example 1 — Beep After a Message
Print a notice, then play the default beep.
C#
using System;
class Program {
static void Main() {
Console.WriteLine("Task finished");
Console.Beep();
Console.WriteLine("(beep)");
}
}
Output
Task finished
(beep)
How It Works
Message first. Users still see text even if sound is off.
Default Beep. No frequency arguments—system default tone.
Marker line. We print (beep) because sound cannot appear in sample output.
Optional cue. Treat audio as secondary feedback.
Example 2 — Two Different Pitches
Play a short low tone then a higher one when supported.
C#
using System;
class Program {
static void Main() {
Console.WriteLine("Low tone");
Console.Beep(400, 150);
Console.WriteLine("High tone");
Console.Beep(1000, 150);
}
}
Output
Low tone
High tone
How It Works
Frequency. 400 Hz then 1000 Hz when the platform allows it.
Duration. 150 ms keeps each beep short.
Text labels. Output shows which tone was requested.
May be silent. Some hosts skip custom Beep calls.
Example 3 — Beep on Invalid Input
Combine validation text with a beep.
C#
using System;
class Program {
static void Main() {
Console.Write("Enter YES: ");
string? s = Console.ReadLine();
if (s != "YES") {
Console.Beep();
Console.WriteLine("Invalid");
} else {
Console.WriteLine("Accepted");
}
}
}
Output
Enter YES: nope
Invalid
How It Works
Sample nope. User types something other than YES.
Beep on error. Sound (if any) pairs with the Invalid message.
Visible fallback. Text always communicates the failure.
Strict match. Comparison is case-sensitive here.
Frequently Asked Questions
No. Support depends on the OS and host. It may be silent.
Frequency is hertz; duration is milliseconds.
Invalid frequency/duration values can throw. Unsupported environments may also fail or no-op.
Only as an extra cue. Always show a clear text message too.