从设置文件c#console应用程序读取用户设置值 [英] Reading User Setting value from setting file c# console application

查看:226
本文介绍了从设置文件c#console应用程序读取用户设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从设置文件读取值时出现空参考错误。



< setting name =   Last_Selected_Vodafone serializeas =  字符串 >  
< value />
< / 设置 >





i在设置文件中有此属性。当我尝试在c中访问它时#



 Properties.Settings.Default.Last_Selected_Vodafone; 





i得到空引用错误..这可能是因为默认值为null并且它是一个日期时间属性......



如何设置

 datetime variable = datetime.now?



任何想法

解决方案

请尝试如下。



注意:如果需要,请进行必要的铸造。

  DateTime  variable = Properties.Settings。默认 .Last_Selected_Vodafone ??  DateTime 。现在; 



??运营商



现场演示: .NET FIDDLE


Null reference error occurs on reading value from setting file.

<setting name="Last_Selected_Vodafone" serializeas="String">
              <value />
          </setting>



i have this property in setting file . when i try to access this in c#

Properties.Settings.Default.Last_Selected_Vodafone;



i am getting null reference error.. that could be because default value is null and its a datetime property......

how can i set

datetime variable = datetime.now ?


any idea

解决方案

Please try is as below.

NOTE: Please do necessary casting if it requires.

DateTime variable = Properties.Settings.Default.Last_Selected_Vodafone ?? DateTime.Now;


?? Operator

LIVE DEMO : .NET FIDDLE


这篇关于从设置文件c#console应用程序读取用户设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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