I am trying to write a program, where I have a province, and it has a lot of properties. When I start the program, it shall read all the lines in the textFile(provinceData.txt), put it into an Array and then put that value into the struct. Now I tried every way I know to convert variables, and I haven't come to a solution. When I start the program, Visual Studio says"the input string has the wrong format".
Here is the code I already got:
public struct provinceStruct001
{
public string name;
public int terrain;
}
static void getProvinceDataFromFile()
{
string[] allLines = File.ReadAllLines("../../save/provinceData.txt");
//puts all the Lines in the Text File into an Array
provinceStruct001 ProvinceStruct001 = new provinceStruct001();
ProvinceStruct001.name = allLines[4 + 1];
ProvinceStruct001.terrain=Convert.ToInt32(Convert.ToString(allLines[8 + 1]));
//8 is the Line in the textFile and +1 because an array starts at 0,
and i cant read line 0 in a text file
}
*
Here is the TextFile:
struct provinceStruct001
{
string name;
Munich //this
int occupier;
0 //this 0=noone 1=rebels 2=foreign_country
int terrain;
0 //and this are the only important lines
0=flatlands,1=forest,2=hilly,3=mountainous
bool isCapital;
false
I thank everyone, who takes the time to help me in advance.
Convert.ToInt32and look at whatallLines[8 + 1]contains.