[Solved] C# – How to assign different lines of File.ReadAllText to individual variables? [closed]


actually your post is kind of “unclear” to readers but I did get your point regarding reading lines from text to variables

I suggest you use File.ReadAllLines, then format your text with each values separated per line

so it goes like this

Source.txt

LOOOALLOOAAL
OOOOOOOAOOOO
LLLLOOOOALLA

then your line of code will be

string[] students = File.ReadAllLines("Source.txt");

thus the values would be

students[0] = LOOOALLOOAAL
students[1] = OOOOOOOAOOOO
students[2] = LLLLOOOOALLA

the code File.ReadAllLines() gets every line of text from your source file until it reaches the endline and stores it into an array of string. if you needed your values for calculations, then you’ll need to parse such values

I just showed you how to get values from text to variables. how you show them as output will be on you.

2

solved C# – How to assign different lines of File.ReadAllText to individual variables? [closed]