我有一个像这样的静态类:
public static class ApplicationList
{
public static List<ApplicationsModel> ApplicationsModels { get; set; }
}
我想在另一个类中使用 ApplicationsModels
class Program
{
static void Main(string[] args)
{
GetApplicationNameFromAppConfigAndAddToApplicationList();
}
private static void GetApplicationNameFromAppConfigAndAddToApplicationList()
{
List<string> applicationName = ConfigurationManager.AppSettings["AppName"].Split(',').ToList();
foreach (var variable in applicationName)
{
ApplicationList.ApplicationsModels.Add(new ApplicationsModel { DateTime = DateTime.MinValue, Name = variable });
}
}
}
但我的 ApplicationList 为空并收到此错误
Object reference not set to an instance of an object.
这是静态 Prpoerty,我们无法从静态 Prpoerty 创建实例