İngilizce dilinde oku

Aracılığıyla paylaş


Console.Beep Yöntem

Tanım

Konsol hoparlöründen bip sesi çalar.

Aşırı Yüklemeler

Beep()

Konsol hoparlöründen bip sesi çalar.

Beep(Int32, Int32)

Konsol hoparlörü aracılığıyla belirtilen frekans ve sürenin bip sesini çalar.

Beep()

Kaynak:
Console.cs
Kaynak:
Console.cs
Kaynak:
Console.cs

Konsol hoparlöründen bip sesi çalar.

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static void Beep();
C#
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static void Beep();
C#
public static void Beep();
Öznitelikler

Özel durumlar

Bu yöntem, kullanıcı arabirimine erişim izni vermeyen SQL Server gibi bir sunucuda yürütüldü.

Örnekler

Aşağıdaki örnekte yöntemi gösterilmektedir Beep . Örnek, komut satırı bağımsız değişkeni olarak 1 ile 9 arasında bir sayı kabul eder ve bu sayıda bip sesi çalar.

C#
// This example demonstrates the Console.Beep() method.
using System;

class Sample
{
    public static void Main(String[] args)
    {
    int x = 0;
//
    if ((args.Length == 1) &&
        (Int32.TryParse(args[0], out x)) &&
        ((x >= 1) && (x <= 9)))
        {
        for (int i = 1; i <= x; i++)
            {
            Console.WriteLine("Beep number {0}.", i);
            Console.Beep();
            }
        }
    else
        {
            Console.WriteLine("Usage: Enter the number of times (between 1 and 9) to beep.");
        }
    }
}
/*
This example produces the following results:

>beep
Usage: Enter the number of times (between 1 and 9) to beep

>beep 9
Beep number 1.
Beep number 2.
Beep number 3.
Beep number 4.
Beep number 5.
Beep number 6.
Beep number 7.
Beep number 8.
Beep number 9.

*/

Açıklamalar

Varsayılan olarak, bip sesi 200 milisaniyelik bir süre boyunca 800 hertz sıklıkta çalar.

Beep , Windows Bip işlevine yapılan çağrıyı sarmalar. Windows'un Windows 7 öncesi sürümlerinde ses üretip Beep üretmediği, 8254 programlanabilir aralık zamanlayıcı yongasının varlığına bağlıdır. Windows 7'den başlayarak, varsayılan ses cihazına bağlıdır.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

Beep(Int32, Int32)

Kaynak:
Console.cs
Kaynak:
Console.cs
Kaynak:
Console.cs

Konsol hoparlörü aracılığıyla belirtilen frekans ve sürenin bip sesini çalar.

C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void Beep(int frequency, int duration);
C#
public static void Beep(int frequency, int duration);

Parametreler

frequency
Int32

Bip sesi sıklığı, 37 ila 32767 hertz arasında.

duration
Int32

Bip sesi milisaniye cinsinden ölçülür.

Öznitelikler

Özel durumlar

frequency 37'den az veya 32767 hertz'den fazladır.

-veya-

duration sıfırdan küçük veya sıfıra eşit.

Bu yöntem, konsola erişime izin vermeyen SQL Server gibi bir sunucuda yürütüldü.

Geçerli işletim sistemi Windows değil.

Örnekler

Bu örnekte, konsol hoparlörü Beep aracılığıyla bir şarkının ilk birkaç notasını yürüterek yöntemini gösterir.

C#
// This example demonstrates the Console.Beep(Int32, Int32) method
using System;
using System.Threading;

class Sample
{
    public static void Main()
    {
// Declare the first few notes of the song, "Mary Had A Little Lamb".
    Note[] Mary =
        {
        new Note(Tone.B, Duration.QUARTER),
        new Note(Tone.A, Duration.QUARTER),
        new Note(Tone.GbelowC, Duration.QUARTER),
        new Note(Tone.A, Duration.QUARTER),
        new Note(Tone.B, Duration.QUARTER),
        new Note(Tone.B, Duration.QUARTER),
        new Note(Tone.B, Duration.HALF),
        new Note(Tone.A, Duration.QUARTER),
        new Note(Tone.A, Duration.QUARTER),
        new Note(Tone.A, Duration.HALF),
        new Note(Tone.B, Duration.QUARTER),
        new Note(Tone.D, Duration.QUARTER),
        new Note(Tone.D, Duration.HALF)
        };
// Play the song
    Play(Mary);
    }

// Play the notes in a song.
    protected static void Play(Note[] tune)
    {
    foreach (Note n in tune)
        {
        if (n.NoteTone == Tone.REST)
            Thread.Sleep((int)n.NoteDuration);
        else
            Console.Beep((int)n.NoteTone, (int)n.NoteDuration);
        }
    }

// Define the frequencies of notes in an octave, as well as
// silence (rest).
    protected enum Tone
    {
    REST   = 0,
    GbelowC = 196,
    A      = 220,
    Asharp = 233,
    B      = 247,
    C      = 262,
    Csharp = 277,
    D      = 294,
    Dsharp = 311,
    E      = 330,
    F      = 349,
    Fsharp = 370,
    G      = 392,
    Gsharp = 415,
    }

// Define the duration of a note in units of milliseconds.
    protected enum Duration
    {
    WHOLE     = 1600,
    HALF      = WHOLE/2,
    QUARTER   = HALF/2,
    EIGHTH    = QUARTER/2,
    SIXTEENTH = EIGHTH/2,
    }

// Define a note as a frequency (tone) and the amount of
// time (duration) the note plays.
    protected struct Note
    {
    Tone     toneVal;
    Duration durVal;

// Define a constructor to create a specific note.
    public Note(Tone frequency, Duration time)
        {
        toneVal = frequency;
        durVal  = time;
        }

// Define properties to return the note's tone and duration.
    public Tone NoteTone { get{ return toneVal; } }
    public Duration NoteDuration { get{ return durVal; } }
    }
}
/*
This example produces the following results:

This example plays the first few notes of "Mary Had A Little Lamb"
through the console speaker.
*/

Açıklamalar

Beep , Windows Bip işlevine yapılan çağrıyı sarmalar. Windows'un Windows 7 öncesi sürümlerinde ses üretip Beep üretmediği, 8254 programlanabilir aralık zamanlayıcı yongasının varlığına bağlıdır. Windows 7'den başlayarak, varsayılan ses cihazına bağlıdır.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1