C#将字符串添加到Stringcollection [英] C# Adding string to Stringcollection

查看:508
本文介绍了C#将字符串添加到Stringcollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用户设置中设置为



In the user Settings is set to

Name:DateEventNames
Type:StringCollection
Scope:User
Value: 



这是我的代码




This is my code

Properties.Settings.Default.DatesEventNames.Add(EventTextBox.Text);





这是我的错误



And this is my error

Object reference not set to an instance of an object



这很奇怪,因为这段代码应该有用,有人可以解释一下为什么这不起作用,并告诉我如何修复它?


This is weird, because this code should of worked, can some one please explain why this didn''t work, and tell me how to fix it?

推荐答案

你没有提供有关这行代码编写位置的详细信息。在它已经初始化EventTextBox的情况下使用它,只有我能看到的其他点是StringCollection的初始化



你做过类似下面的初始化吗?



You have not given much details about where this line of code is written. COnsidering it is used where EventTextBox is already initialized, only other point I can see is initialization of StringCollection

Have you done initialization something like below?

StringCollection myCollection = new StringCollection();





另外,请注意,在添加时,属性名称与 DateEventNames 在定义时与 DatesEventNames 不同。请检查。



希望有所帮助

Milind



Also, note that name of the property is different as DateEventNames at definition vs. DatesEventNames when you adding. Just check.

Hope that helps
Milind


我会开始阅读这个



C#写入app.config文件 [ ^ ]
I would start to have a read of this

C# writing to app.config file[^]


这篇关于C#将字符串添加到Stringcollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆