Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading parameters from External file - C#

Tags:

c#

readfile

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?

like image 283
mouthpiec Avatar asked May 15 '10 08:05

mouthpiec


People also ask

How to read values from a file in C?

In order to read information from a file, or to write information to a file, your program must take the following actions. 1) Create a variable to represent the file. 2) Open the file and store this "file" with the file variable. 3) Use the fprintf or fscanf functions to write/read from the file.

How to read a file and write to another file in C?

#include <iostream> #include <stdlib. h> using namespace std; int main() { char ch;// source_file[20], target_file[20]; FILE *source, *target; char source_file[]="x1. txt"; char target_file[]="x2. txt"; source = fopen(source_file, "r"); if (source == NULL) { printf("Press any key to exit...

What is the first parameter of read function used in file handling?

The file read operations can be performed using functions fscanf or fgets. Both the functions performed the same operations as that of scanf and gets but with an additional parameter, the file pointer.

What are file parameters?

Parameter files are ASCII files with the extension . par. They are extensively used in SDSS data for storing moderate amounts of data in a form that is both human and machine readable. Parameter files are sometimes informally called 'Yanny' files, or, more rarely, 'FTCL' files.


1 Answers

var settings = 
     from line in File.ReadAllLines("params.txt")
     let parameters = line.Split('=')
     select new KeyValuePair<string, string>(parameters[0], parameters[1]);
like image 99
Darin Dimitrov Avatar answered Oct 25 '22 14:10

Darin Dimitrov