[C#] Save MySQL Connection
#4

Save it to a file.


class ConfigManager
{
public struct config
{
public string key;
public string value;
};
public static List ConfigList = new List();

public void readList(string filename)
{
StreamReader sr = new StreamReader(filename);
string line;
while ((line = sr.ReadLine()) != null)
{
if (line[0] == #)
{
continue;
}
string[] data = line.Split(=);
if (data.Length == 2)
{
config cfg = new config();
cfg.key = data[0];
cfg.value = data[1];
ConfigList.Add(cfg);
}
}
}
public void saveFile(string filename)
{
StreamWriter sw = new StreamWriter(filename);
for (int i = 0; i < ConfigList.Count; i++)
{
config cfg = new config();
cfg = ConfigList[i];
sw.WriteLine(cfg.key+"="+cfg.value);
}

}
public string getString(string key)
{
for (int i = 0; i < ConfigList.Count; i++)
{
config cfg = new config();
cfg = ConfigList[i];
if (cfg.key == key)
return cfg.value;
}
return "";
}

public int getInt(string key)
{
for (int i = 0; i < ConfigList.Count; i++)
{
config cfg = new config();
cfg = ConfigList[i];
if (cfg.key == key)
return int.Parse(cfg.value);
}
return 0;
}
}



Messages In This Thread
[No subject] - by Nikolee - 05-23-2012, 06:29 PM
[No subject] - by HateMe - 05-23-2012, 06:31 PM
[No subject] - by Wizatek - 05-23-2012, 06:39 PM
[No subject] - by someone - 05-23-2012, 06:41 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)