简体   繁体   English

ASP.net中的应用程序变量(c#)。

[英]The application variable in ASP.net(c#).

I have a problem with the application state in Asp.net. 我在Asp.net中的应用程序状态有问题。 I need a list of Strings that i would use in different forms in the same application. 我需要一个字符串列表,我将在同一个应用程序中以不同的形式使用。 Here I add the list: 在这里我添加列表:

Application.Add("users", new List<String>());

In a new form I try to add a string to the list, but I get NullReferenceException in the second line of the code below. 在一个新的形式我尝试添加一个字符串到列表,但我在下面的代码的第二行得到NullReferenceException。

 List<String> ls=(List<String>) Application.Get("users");
            ls.Add(TextBox4.Text);

In the first slot of code the string is empty because of {new List<String>()} . 在代码的第一个插槽中,由于{new List<String>()} ,字符串为空。 You need to add the string in the list. 您需要在列表中添加字符串。 Only after that, call the Application variable in another form to avoid the NullReferenceException Exception. 只有在那之后,以另一种形式调用Application变量以避免NullReferenceException异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM