Reading parameters from an external file - C #

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

parA = 5
parB = hello
etc

Can you ask how I can do this?

+5
source share
3 answers

I know that this is not what you specifically asked, but if you have a choice, I would go with the configuration of the XML application.

It has a lot of resources, but here is a pretty simple example:

http://www.c-sharpcorner.com/UploadFile/dolson/XMLConfigInWinForms11262005014845AM/XMLConfigInWinForms.aspx

+1
source
var settings = 
     from line in File.ReadAllLines("params.txt")
     let parameters = line.Split('=')
     select new KeyValuePair<string, string>(parameters[0], parameters[1]);
+7
source

Read each line and divide it by the first occurrence "=".

+1
source

All Articles