Reading parameters from External file - C#

mouthpiec picture mouthpiec · May 15, 2010 · Viewed 8.1k times · Source

I am writing an application using C# and I would like to read some parameters from an external file like for example a text file. The parameters will be saved in the file in the form of

parA = 5
parB = hello
etc

Can you pleas suggest a way how I can do this?

Answer

Darin Dimitrov picture Darin Dimitrov · May 15, 2010
var settings = 
     from line in File.ReadAllLines("params.txt")
     let parameters = line.Split('=')
     select new KeyValuePair<string, string>(parameters[0], parameters[1]);