N
N
ne_pedofil_chesna2020-05-26 17:57:42
C++ / C#
ne_pedofil_chesna, 2020-05-26 17:57:42

How to determine time difference in milliseconds between two animation slides in C# environment?

The animation is set per slide by counter K. It is necessary to determine the time in milliseconds between 7 and 9 slides.
Here is the part of the code
if (k == 7)
{
pictureBox1.Image = Resources._7;
var x = DateTime.Now.ToString("ss:fff" );
}
if (k == 8)
{
pictureBox1.Image = Resources._8;
}
if (k == 9)
{
pictureBox1.Image = Resources._7;
var y = DateTime.Now.ToString("ss:fff" );
TimeSpan diff1 = x - y;
Gives an error "The name x does not exist in this context"
When I try to fix this error, it says that the operation "-" cannot be performed with variables of type string.
Help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#, 2020-05-26
@ne_pedofil_chesna

Gives the error "The name x does not exist in this context"
right
if (k == 7)
{
        pictureBox1.Image = Resources._7;
        var x = DateTime.Now.ToString("ss:fff" );
}
// после этой фигурной скобки x уже не существует
ps to think what is the difference
var x = "";
if (k == 7)
{
        pictureBox1.Image = Resources._7;
        x = DateTime.Now.ToString("ss:fff" );
}

pps is true, more about lines - there are lines for lines, +but this is gluing lines. there is no dynamic type conversion in C# (although there is a default type casting , but not always)
here is a useful article on how you can measure time in C# https://habr.com/ru/post/226279/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question