I have a program which in order to function needs the user to input two directories (e.g. the Desktop and Picture directory). This works, but upon closing and relaunching the program, the user needs to re-enter the directories, as the program does not remember the directories from the last time it ran. Obviously.
Now my plan was to create a file to which the program writes the directories so that once the user launches the program it checks if the file exists and if so reads it and gets the two directories it needs.
I tried creating a plain .txt, but as there are two directories and either one or the other can be written to the .txt first it was hard to read from it and get the correct directory. To visualize my .txt can look like this:
C://Dir1 C://Dir2

or
C://Dir2 C://Dir1 
depending on which directory the user selected first.

Tl;Dr I want to save two directories for consequent launches of the program, but when reading the two directories I need to be able to know which directory is which.
I am working with .NET Core 3.1
either one or the other can be written to the .txt first
This is a wrong assumption. You decide in your code in which order they are written and you always write both of them, never one of them only.
Example code for writing:
string a = null;
string b = "c:\\something";
File.WriteAllText("myconfig.txt", a+ "\r\n" + b);
Example code for reading:
string[] filecontent = File.ReadAllLines("myconfig.txt");
a = filecontent[0];
if (a==string.Empty) a = null;
b = filecontent[1];
if (b==string.Empty) b = null;
Console.WriteLine(a);
Console.WriteLine(b);