Search code examples
c#intstopwatch

Convert Stopwatch to int


I have a little snag , I ought to Convert my Stopwatch into Int ,

Stopwatch czasAlg = new Stopwatch();

czasAlg.Start(); //Do something czasAlg.Stop();

Int32 mojCzas = Convert.ToInt32(czasAlg); //I try to convert but it does't work.

// Int32 mojCzas = Convert.ToInt32(czasAlg.ToString()); //It does't work too.

Any Ideas to solve the problem ?


Solution

  • Putting together the pieces from your question and comments, it seems you want this:

    Stopwatch czasAlg = new Stopwatch();
    czasAlg.Start(); 
    //Do something 
    czasAlg.Stop();
    double timeInSecondsPerN=czasAlg.Elapsed.TotalSeconds/n;