Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a code that takes the data from the dictionary and writes it into a label, but in which they are. And I need to do so that it is recorded in the format of minutes, that is:

minutes: seconds

mm: ss

Here is the code that performs the mapping to the label:

private void updateRatingLabels2()
    {
        var tops = AllNames2()
          .OrderBy(pair => pair.Value) 
          .ThenBy(pair => pair.Key, StringComparer.Ordinal) 
          .Take(5)   
          .ToArray();


        for (int i = 23; i <= 27; ++i)
            Controls.Find($"label{i}", true).First().Text = "";

        for (int i = 33; i <= 37; ++i)
            Controls.Find($"label{i}", true).First().Text = "";


        for (int i = 0; i < tops.Length; ++i)
        {
            Controls.Find($"label{i + 23}", true).First().Text = tops[i].Key;
            Controls.Find($"label{i + 33}", true).First().Text = tops[i].Value.ToString();
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
184 views
Welcome To Ask or Share your Answers For Others

1 Answer

If the value within the dictionary is a string of datetime you could try using DateTime.Parse like this:

var val = tops[i].Value.ToString();
 Controls.Find($"label{i + 33}", true).First().Text = DateTime.Parse(val).ToString("mm:ss") ;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...