Answer the question
In order to leave comments, you need to log in
C# How to correctly read data into an array from a file using StreamReader?
According to the assignment, there is a base class Human, which has the variables Name, LastName, Age and 3 inheriting classes Student, Teacher, TaxiDriver, which also have their own parameters. It is necessary, reading data from one .txt file, to fill in 3 objects of the student, teacher, and driver, having the following file structure:
Student SOne
{ “Name”: “Andrey”,
“LastName”: “Egorov”,
“studentId”: “123456”
“Age”: “20”};
Teacher TOne
{ “Name”: “Ivan”,
“LastName”: “Crunchy”,
“Subject”: “OOP”,
“Age”: “32”};
TaxiDriver DOne
{ “Name”: “Alexander”,
“LastName”: “Grey”,
“TaxiName”: “777”,
“Age”: “40”};
Answer the question
In order to leave comments, you need to log in
You read line by line using StreamReader.ReadLine() and regularly get 2 values from each line, discarding all other characters (brackets, commas, colons). How to construct parsing and interpretation of these two values is up to you. But I would make a state machine on 3 states: Reading the header, reading fields, end of record.
P.s. Yes, I see that this is JSON, but this is a trap, the task does not say about it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question