Answer the question
In order to leave comments, you need to log in
How to output key and value from dictionary to label?
There are 10 labels and a dictionary that consists of the key-name of the player, label-record (in seconds). The first 5 labels are made for names (i.e. as a table of records), and the remaining 5 labels are for results. I need to display these from the dictionary data and sort them by label, the fewer seconds, the higher the person in the ranking. You need to do something so that the player who is in 1st place displays his name and result.
10 labels in the table are arranged like this (I write label numbers):
1 6
2 7
3 8
4 9
5 10
There is also a code on how to make a dictionary (may come in handy):
private static Dictionary<string, int> AllNames()
{
return File
.ReadLines(@"C:\Users\HP\Desktop\картинки\results.txt")
.Where(line => string.IsNullOrWhiteSpace(line))
.Select(item => item.Split(' '))
.ToDictionary(items => items[0],
items => int.Parse(items[1]));
}
Answer the question
In order to leave comments, you need to log in
Don't use too many Labels, put them in a ListBox and you'll be fine. Appearance can be customized - background BackColor=Control, borders BorderStyle=None. When adding an entry to the list, you can convert it to a string as needed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question