From the course: C# File System Tips and Tricks
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Reading a config file - C# Tutorial
From the course: C# File System Tips and Tricks
Reading a config file
- [Instructor] Now that we're able to save the paths to each of the folders we create inside of a config.text, let's take a look at how we can read this data out, and allow us to modify these paths before we run the program itself. Let's switch back over to the program class. At the bottom, we're going to create a new public method. We'll set its to return type to void, and call this ReadConfig. The first thing we're going to do is get each of the lines of text as a string array. We'll create a variable called, lines, and we're going to use the File.ReadAllLines and pass in the configFile field as the path. Once we have this array of strings, let's go ahead and create a new variable called total, and set it equal to lines.Length. Now, let's go ahead and create a new for loop. We'll set var i equal to zero, we'll make i less than total, and we'll iterate i by one over each loop. Now let's create a variable called pathString and we'll set it equal to the lines array and we use i for the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.