Console.Beep Console.Beep Console.Beep Console.Beep Method

정의

콘솔 스피커를 통해 경고음을 재생합니다.Plays the sound of a beep through the console speaker.

오버로드

Beep() Beep() Beep() Beep()

콘솔 스피커를 통해 경고음을 재생합니다.Plays the sound of a beep through the console speaker.

Beep(Int32, Int32) Beep(Int32, Int32) Beep(Int32, Int32) Beep(Int32, Int32)

지정한 시간 동안 지정한 주파수로 콘솔 스피커를 통해 경고음을 재생합니다.Plays the sound of a beep of a specified frequency and duration through the console speaker.

Beep() Beep() Beep() Beep()

콘솔 스피커를 통해 경고음을 재생합니다.Plays the sound of a beep through the console speaker.

public:
 static void Beep();
public static void Beep ();
static member Beep : unit -> unit
Public Shared Sub Beep ()

예외

이 메서드가 사용자 인터페이스에 대한 액세스를 허용하지 않는 SQL Server와 같은 서버에서 실행되었습니다.This method was executed on a server, such as SQL Server, that does not permit access to a user interface.

예제

다음 예제는 Beep 메서드.The following example demonstrates the Beep method. 이 예제에서는 명령줄 인수로 1부터 9 까지의 숫자를 받고 해당 횟수를 경고음을 재생 합니다.The example accepts a number from 1 through 9 as a command line argument, and plays the beep that number of times.

// This example demonstrates the Console.Beep() method.
using namespace System;
int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   int x = 0;
   
   //
   if ( (args->Length == 2) && (Int32::TryParse( args[ 1 ],  x ) == true) && ((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.

*/
// 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) == true) &&
        ((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.

*/
' This example demonstrates the Console.Beep() method.
Class Sample
   Public Shared Sub Main(args() As String)
      Dim x As Integer = 0
      Dim i As Integer
      '
      If      (args.Length = 1) _
      AndAlso (Int32.TryParse(args(0), x) = True) _
      AndAlso ((x >= 1) AndAlso (x <= 9)) Then
         For i = 1 To x
            Console.WriteLine("Beep number {0}.", i)
            Console.Beep()
         Next i
      Else
         Console.WriteLine("Usage: Enter the number of times (between 1 and 9) to beep.")
      End If
   End Sub
End Class
'
'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.
'

설명

기본적으로 경고음 800 헤르츠 빈도로 200 밀리초 동안 재생 됩니다.By default, the beep plays at a frequency of 800 hertz for a duration of 200 milliseconds.

참고

Beep 메서드가 64 비트 버전의 Windows Vista 및 Windows XP에서 지원 되지 않습니다.The Beep method is not supported on the 64-bit editions of Windows Vista and Windows XP.

Beep Windows에 대 한 호출을 래핑하고 함수에 경고음을입니다.Beep wraps a call to the Windows Beep function. 여부를 Beep Windows 7 8254 프로그램 가능 간격 타이머 칩에 의존 하기 전에 버전의 Windows에서 소리를 생성 합니다.Whether Beep produces a sound on versions of Windows before Windows 7 depends on the presence of a 8254 programmable interval timer chip. Windows 7부터 기본 사운드 디바이스에 따라 다르겠지요.Starting with Windows 7, it depends on the default sound device.

Beep(Int32, Int32) Beep(Int32, Int32) Beep(Int32, Int32) Beep(Int32, Int32)

지정한 시간 동안 지정한 주파수로 콘솔 스피커를 통해 경고음을 재생합니다.Plays the sound of a beep of a specified frequency and duration through the console speaker.

public:
 static void Beep(int frequency, int duration);
public static void Beep (int frequency, int duration);
static member Beep : int * int -> unit
Public Shared Sub Beep (frequency As Integer, duration As Integer)

매개 변수

frequency
Int32 Int32 Int32 Int32

경고음의 주파수이며 해당 범위는 37 - 32767헤르츠입니다.The frequency of the beep, ranging from 37 to 32767 hertz.

duration
Int32 Int32 Int32 Int32

경고음의 지속 시간(밀리초)입니다.The duration of the beep measured in milliseconds.

예외

frequency가 37헤르츠보다 작거나 32767헤르츠보다 큽니다.frequency is less than 37 or more than 32767 hertz.

또는-or- duration가 0보다 작거나 같습니다.duration is less than or equal to zero.

이 메서드가 콘솔에 대한 액세스를 허용하지 않는 SQL Server와 같은 서버에서 실행되었습니다.This method was executed on a server, such as SQL Server, that does not permit access to the console.

현재 운영 체제는 Windows가 아닙니다.The current operating system is not Windows.

예제

이 예제에서는 Beep 콘솔 스피커를 통해 song의 첫 번째 몇 메모를 재생 하 여 메서드.This example demonstrates the Beep method by playing the first few notes of a song through the console speaker.

// This example demonstrates the Console.Beep(Int32, Int32) method
using namespace System;
using namespace System::Threading;
ref class Sample
{
protected:

   // Define the frequencies of notes in an octave, as well as 
   // silence (rest).
   enum class 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.
   enum class Duration
   {
      WHOLE = 1600,
      HALF = Duration::WHOLE / 2,
      QUARTER = Duration::HALF / 2,
      EIGHTH = Duration::QUARTER / 2,
      SIXTEENTH = Duration::EIGHTH / 2
   };


public:

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

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


      property Tone NoteTone 
      {

         // Define properties to return the note's tone and duration.
         Tone get()
         {
            return toneVal;
         }

      }

      property Duration NoteDuration 
      {
         Duration get()
         {
            return durVal;
         }

      }

   };


protected:

   // Play the notes in a song.
   static void Play( array<Note>^ tune )
   {
      System::Collections::IEnumerator^ myEnum = tune->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Note n =  *safe_cast<Note ^>(myEnum->Current);
         if ( n.NoteTone == Tone::REST )
                  Thread::Sleep( (int)n.NoteDuration );
         else
                  Console::Beep( (int)n.NoteTone, (int)n.NoteDuration );
      }
   }


public:
   static void Main()
   {
      
      // Declare the first few notes of the song, "Mary Had A Little Lamb".
      array<Note>^ Mary = {Note( Tone::B, Duration::QUARTER ),Note( Tone::A, Duration::QUARTER ),Note( Tone::GbelowC, Duration::QUARTER ),Note( Tone::A, Duration::QUARTER ),Note( Tone::B, Duration::QUARTER ),Note( Tone::B, Duration::QUARTER ),Note( Tone::B, Duration::HALF ),Note( Tone::A, Duration::QUARTER ),Note( Tone::A, Duration::QUARTER ),Note( Tone::A, Duration::HALF ),Note( Tone::B, Duration::QUARTER ),Note( Tone::D, Duration::QUARTER ),Note( Tone::D, Duration::HALF )};
      
      // Play the song
      Play( Mary );
   }

};

int main()
{
   Sample::Main();
}

/*
This example produces the following results:

This example plays the first few notes of "Mary Had A Little Lamb" 
through the console speaker.
*/
// 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.
*/
' This example demonstrates the Console.Beep(Int32, Int32) method
Imports System.Threading

Class Sample
   Public Shared Sub Main()
      ' Declare the first few notes of the song, "Mary Had A Little Lamb".
      Dim Mary As Note() =  { _
            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)
   End Sub
   
   ' Play the notes in a song.
   Protected Shared Sub Play(tune() As Note)
      Dim n As Note
      For Each n In  tune
         If n.NoteTone = Tone.REST Then
            Thread.Sleep(CInt(n.NoteDuration))
         Else
            Console.Beep(CInt(n.NoteTone), CInt(n.NoteDuration))
         End If
      Next n
   End Sub
   ' 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
   End Enum 'Tone
   
   ' 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
   End Enum 'Duration
   
   ' Define a note as a frequency (tone) and the amount of 
   ' time (duration) the note plays.
   Protected Structure Note
      Private toneVal As Tone
      Private durVal As Duration
      
      ' Define a constructor to create a specific note.
      Public Sub New(frequency As Tone, time As Duration)
         toneVal = frequency
         durVal = time
      End Sub
      
      ' Define properties to return the note's tone and duration.
      Public ReadOnly Property NoteTone() As Tone
         Get
            Return toneVal
         End Get
      End Property
      
      Public ReadOnly Property NoteDuration() As Duration
         Get
            Return durVal
         End Get
      End Property
   End Structure 'Note '
'This example produces the following results:
'
'This example plays the first few notes of "Mary Had A Little Lamb" 
'through the console speaker.
'
End Class

설명

Beep Windows에 대 한 호출을 래핑하고 함수에 경고음을입니다.Beep wraps a call to the Windows Beep function. 여부를 Beep Windows 7 8254 프로그램 가능 간격 타이머 칩에 의존 하기 전에 버전의 Windows에서 소리를 생성 합니다.Whether Beep produces a sound on versions of Windows before Windows 7 depends on the presence of a 8254 programmable interval timer chip. Windows 7부터 기본 사운드 디바이스에 따라 다르겠지요.Starting with Windows 7, it depends on the default sound device.

참고

Beep 메서드가 64 비트 버전의 Windows Vista 및 Windows XP에서 지원 되지 않습니다.The Beep method is not supported on the 64-bit editions of Windows Vista and Windows XP.

적용 대상