I do laboratory- "Access restriction on the speed of typing a phrase on the keyboard."

Suppose in a text file I keep records:

  • Nikita - 3--41
  • Vasya - 3--43
  • Petr - 5--52

Nikita is the username; 3-number key phrase (phrases are selected from another file); 41-speed phrase typing

This data is entered in the registration form and saved to a text file. For the second form of the login form, I need to separately write in one DYNAMIC array (collection) names, in the second line number, and in the third time. How do i implement this? Thanks in advance for your help.

  • And what's the point of splitting data into three arrays? Why not one list of objects? - VladD
  • I need to put names in the ComboBox, for example. The number of the key phrase to use as an index in the array to receive this phrase. Well, time for comparison with the time for which the user to enter a phrase at the entrance. It seemed to me that it would be more convenient to divide, but these are just my assumptions. If you have any ideas and advice, then I will be happy to hear it. - N.Khlystov
  • one
    Of course. Get an object that describes the user and his information. And a list of these objects. For display in the combo box, you can specify the contents of which field to show (done differently, depending on your graphical framework). Pros - you do not need to worry about synchronizing the three lists all the time. - VladD

1 answer 1

And if through List. Create a class:

class DataSpeed { public string name {get; set;} public string number {get; set;} public string time {get; set;} } 

And then in a three-dimensional array:

 static void Main() { List<DataSpeed> DS = new<DataSpeed>(); StreamReader fs = new StreamReader(@"D:\1.txt"); while (true) { string temp = fs.ReadLine(); if(temp == null) break; DS.Add(new DataSpeed() { name = temp.Split('--')[0], number = temp.Split('--')[1], temp.Split('--')[2] }); } } 

The data is now connected and you can pull out separately from the list everything you need for the same combo box.

  • 2
    Only you forgot to close StreamReader . Well, in general, it is not needed: (from line in File.ReadLines(@"D:\1.txt") let parts = line.Split("---") select new DataSpeed() { name = parts[0], number = parts[1], time = parts[2] }).ToList() . - VladD
  • Thank you so much for helping both of you. - N.Khlystov
  • @ N.Khlystov: If it helped you, do not forget to put a green daw (left) to the answer. - VladD
  • [Bore-ON] only the array you have is not three-dimensional, but one-dimensional, with 3 fields for each element, with a stretch it can be considered two-dimensional. StreamReader should be StreamReader into using [Bore-OFF] but generally something like this, but in short, VladD has already demonstrated. - rdorn