I created a class Settingsthat I use to edit my application in a file .ini. My file is Settings.inias follows:
[ACCOUNT]
login=xyz
password=xyz
locations=1,2,5,8
Now I get the following values:
class Settings {
public static IniFile Config = new IniFile(Directory.GetCurrentDirectory() + @"\Settings.ini");
public static string Login { get { return Config.Read("login", "ACCOUNT"); } set { Config.Write("login", "ACCOUNT"); } }
public static string Password { get { return Config.Read("password", "ACCOUNT"); } set { Config.Write("password", "ACCOUNT"); } }
public static int[] Locations { get { return Array.ConvertAll(Config.Read("locations", "ACCOUNT").Split(','), s => int.Parse(s)); } set { Config.Write("locations", "ACCOUNT"); } }
}
The problem is that my file Settings.inihas empty spaces:
locations=
My variable Settings.Locationsreturns nullinstead of an empty array. I tried to do something like this:
public static int[] Locations
{
get { return new int[] {Array.ConvertAll(Config.Read("locations", "ACCOUNT").Split(','), s => int.Parse(s))}; }
set { Config.Write("locations", "ACCOUNT"); }
}
But that just doesn't work. I cannot convert int [] to int. Do you have any idea how I can return an empty array?
source
share