当前位置: 移动技术网 > IT编程>开发语言>.net > 从 exe.config 读取appSettings 中的配置数据

从 exe.config 读取appSettings 中的配置数据

2019年03月20日  | 移动技术网IT编程  | 我要评论

林永健小品全集,珍爱网骗人,三星麦迪逊

右键解决方案,添加引用--> system.configuration.dll

 

在exe.config 中添加数据

<appsettings>
    <add key="ip" value="0.0.0.0" />    
<add key="port" value="1234" /> </appsettings>

 

读取添加的配置数据

if ((true == ipaddress.tryparse(configurationmanager.appsettings["ip"], out ipaddress alarmip))&& (true == int.tryparse(configurationmanager.appsettings["port"], out int alarmport)))
{//有外部配置,用外部配置指定地址
       jtudpt = new jtudpt("udp", alarmip.tostring(), alarmport);
}
else
{//无外部配置,用默认地址和端口
       jtudpt = new jtudpt("udp", "0.0.0.0", 1236);//服务器
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网