Új hozzászólás Aktív témák

  • nmate91

    tag

    válasz Pörp #8012 üzenetére

    using System;
    using System.Threading;

    namespace ConsoleApp1
    {
    class Program
    {
    static int Increase(int count)
    {
    do
    {
    while (!Console.KeyAvailable)
    {
    Console.WriteLine($"count: {count++}");
    Thread.Sleep(25);
    }
    } while (Console.ReadKey(true).Key != ConsoleKey.Spacebar);
    return count;
    }

    static int Decrease(int count)
    {
    do
    {
    while (!Console.KeyAvailable)
    {
    Console.WriteLine($"count: {count--}");
    Thread.Sleep(25);
    }
    } while (Console.ReadKey(true).Key != ConsoleKey.Spacebar);
    return count;
    }

    static void Main(string[] args)
    {
    Console.WriteLine("Press Space to change, and ESC to stop");
    do
    {
    int count = 0;
    count = Increase(count);
    count = Decrease(count);
    } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
    }
    }
    }

    Hasonlo, decrease utan megall, ujra spacet nyomva indul, nullarol. Ha nem nullarol kell, csak ki kell tenni eggyel kijjebb a count deklaralast. Ha kell az 1000 hatarnak, csak a do while-nal kondiciokent kikotod.

    [ Szerkesztve ]

Új hozzászólás Aktív témák