How to bind data that is saved to a file with other data that is saved to another file c#
Why don't you create file per user ? You can just change "SuggestingDifficulty" functions to get the username and use it as file name ?
public static UserDifficulty SuggestingDifficulty(string userName)
{
ToFile objnew = SaveToFile.DeserializeLastTest($"{userName}.txt");
Console.WriteLine($"Last time you did the test on {objnew.UserDifficulty} level and got {objnew.TotalScore}/{objnew.NumberOfQuestions}");
}
and
public static void SerializeLastTest(int numberOfQuestions, int totalScore, UserDifficulty userDifficulty,string userName)
{
ToFile obj = new ToFile(numberOfQuestions, userDifficulty, totalScore);
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("${userName}.txt", FileMode.Create, FileAccess.Write);
formatter.Serialize(stream, obj);
stream.Close();
}
public static ToFile DeserializeLastTest(string userName)
{
Stream stream = new FileStream($"{userName}.txt", FileMode.Open, FileAccess.Read);
IFormatter formatter = new BinaryFormatter();
ToFile objnew = (ToFile)formatter.Deserialize(stream);
stream.Close();
return objnew;
}