Загрузка...

Как вывести элемент массива из метода?

Тема в разделе C# создана пользователем papapahom 11 окт 2022. 118 просмотров

  1. papapahom
    papapahom Автор темы 11 окт 2022 628 16 фев 2019
    Итак, есть метод(че то насрал тут):
    C#
    static int[] SoundFourthOctave()
    {
    int[] fourthOctave = new int[] { 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494 };
    Console.Beep(fourthOctave[0], 200);
    }
    Есть switch-case
    C#
    switch (music.Key)
    {
    case ConsoleKey.S:
    {
    SoundFourthOctave();
    break;
    }
    case ConsoleKey.X:
    {
    SoundFourthOctave();
    break;
    }
    case ConsoleKey.D:
    {
    SoundFourthOctave();
    break;
    }
    Как вывести нужный мне элемент массива вместе со звуком?
    То есть должно быть что-то вроде, но должен еще выводиться звук:
    C#
    switch (music.Key)
    {
    case ConsoleKey.S:
    {
    SoundFourthOctave(fourthOctave[0], 200);
    break;
    }
    case ConsoleKey.X:
    {
    SoundFourthOctave(fourthOctave[1], 200);
    break;
    }
    case ConsoleKey.D:
    {
    SoundFourthOctave(fourthOctave[2], 200;
    break;
    }
    Прошу не пинайте, пытался разобраться, но видимо что-то не так понял
     
    11 окт 2022 Изменено
  2. vtlstolyarov
    vtlstolyarov 12 окт 2022 474 8 янв 2022
    papapahom,
    C#
    int[] fourthOctave = new int[] { 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494 };
    void SoundFourthOctave(int index)
    {
    Console.Beep(fourthOctave[index], 200);
    }
    switch (music.Key)
    {
    case ConsoleKey.S:
    {
    SoundFourthOctave(0);
    break;
    }
    case ConsoleKey.X:
    {
    SoundFourthOctave(1);
    break;
    }
    case ConsoleKey.D:
    {
    SoundFourthOctave(2);
    break;
    }
     
Загрузка...
Top