-1

私はやろうと思っていました:

int intCount = 0;
int intConstant = ...;

while(true)
{
    Console.WriteLine(intCount / intConstant + " seconds");
}

しかし、ストップウォッチを秒単位でカウントするための定数を計算する方法がわかりません。

4

3 に答える 3

3

ループは使用しないでください。これはプロセッサ固有のものです。StopWatchクラスをより適切に使用します。

var watch = StopWatch.StartNew();

while(true)
{
    Console.WriteLine(watch.ElapsedMilliseconds / 1000f + " seconds");
}
于 2013-07-12T19:08:34.953 に答える
1

System.Diagnostics 名前空間で StopWatch クラスを使用できます

        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        Thread.Sleep(10000);
        stopWatch.Stop();
        // Get the elapsed time as a TimeSpan value.
        TimeSpan ts = stopWatch.Elapsed;

        // Format and display the TimeSpan value. 
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
        Console.WriteLine("RunTime " + elapsedTime);
于 2013-07-12T19:11:22.543 に答える
0

あなたが望むものを推測して、次のようにします:

Stopwatch sw = new Stopwatch();
sw.Start();

while(true)
{
    Console.WriteLine(sw.ElapsedMilliseconds / 1000 + " seconds");
}
于 2013-07-12T19:08:43.220 に答える