C# Config file reader
/
0 Comments
The following is a simple C# function used to read a config file into a dictionary. I'm making it available on here in part for others, but mostly for our own future use.
This function requires that System.Collections.Generic, and System.IO be included in the file where it lives. Config files must contain a single setting per line in the format of: "key:value"
Please code responsibly :P
This function requires that System.Collections.Generic, and System.IO be included in the file where it lives. Config files must contain a single setting per line in the format of: "key:value"
Please code responsibly :P
Dictionary<string, string> ReadConfigFile(string path) { Dictionary<string, string> configs = new Dictionary<string, string>(); int counter = 0; string line; System.IO.StreamReader file = new System.IO.StreamReader(path); while ((line = file.ReadLine()) != null) { string[] words = line.Split(':'); configs.Add(words[0], words[1]); counter++; } file.Close(); return configs; }


