I want to initialize an array–I don’t know how big it will be. then set it in a condition
so I’ve got:
string[] my_string;
if(x==2)
{
my_string=File.ReadAllLines("file.txt");
}
string new_string=my_string[1];
It’s telling me I’ve an unassigned local variable, because it’s in the condition. How do I get around this?
Why not Create a List instead and then utilize the File.ReadAllLines(“file.txt”)
also are you including the FilePath along with file.txt
here is a free code snippet for you to use I use this alot when I want to load a TextFile into a List as one bulk load…
from there you can check in the debugger or add a quickwatch to lstLinesFromFile and see all the text that was loaded. each line from there will be accessed link ordinal so use a for loop or foreach loop