要从WPF中的app.config获取List<string>值集合,您需要使用ConfigurationManager类。以下是一个示例:
<appSettings>
<add key="MyList" value="item1,item2,item3" />
</appSettings>
</configuration>
using System;
using System.Collections.Generic;
using System.Configuration;
namespace MyWPFApp
{
public class MySettings
{
public static List<string> MyList
{
get
{
string setting = ConfigurationManager.AppSettings["MyList"];
return new List<string>(setting.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
}
}
}
}
using System;
using System.Collections.Generic;
namespace MyWPFApp
{
public class Program
{
public static void Main(string[] args)
{
List<string> myList = MySettings.MyList;
foreach (string item in myList)
{
Console.WriteLine(item);
}
}
}
}
这将输出:
item1
item2
item3
这就是如何从WPF中的app.config获取List<string>值集合的方法。
领取专属 10元无门槛券
手把手带您无忧上云