string connect = DataModal.Properties.Settings.Default.StockManageSystemConnectionString;
Dictionary<string, string> dictionary = connect.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToDictionary(x => x.Split('=')[0], x => x.Split('=')[1]);
foreach (KeyValuePair<string, string> pair in dictionary)
Console.WriteLine(pair.Key + ":" + pair.Value);
Console.WriteLine("uid的值是:" + dictionary["uid"]);
connect 是连接字符串。
但是如果分别取到,分别赋值的话,应该首先完成上面,然后根据new一个List存相应需要的值。
demo:
string connect = DataModal.Properties.Settings.Default.StockManageSystemConnectionString;
Dictionary<string, string> dictionary = connect.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToDictionary(x => x.Split('=')[0], x => x.Split('=')[1]);
List<string> test = new List<string>(dictionary.Values);
for (int i = 0; i < test.Count; i++)
{
Server.Text = test[0];
Sqlname.Text = test[2];
Pass.Text = test[4];
Account.Text = test[3];
}