我们如何声明应用程序变量. [英] How can we declare application variable.

查看:69
本文介绍了我们如何声明应用程序变量.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,
早安.
今天我又遇到了一个问题.

如何声明应用程序级别的变量?

我的客户下载了文件.
下载文件名格式是这样的

abc_ABC_DDMMYYY1

如您所见,在日期之后有一个变量1.
每次我的客户端下载文件时,此变量都需要增加.

我想添加对date的检查.当日期更改时,此变量设置为1.
每当我的客户端下载文件时,此变量就必须增加其值.

我该怎么办...

例如
第一次下载名称为...的文件

abc_ABC_DDMMYYY1

第二次
abc_ABC_DDMMYYY2

第三次
abc_ABC_DDMMYYY3.


Hi friends,
Good Morning.
Today i am back with one more problem.

how can we declare application level variable?

My client download a file.
the download file name format is such like this

abc_ABC_DDMMYYY1

as you can see after date there is a variable 1.
every time when my client download file.this variable need to get increment.

i want to add check on date.that when date get changed.this variable set to 1.
and again whenever my client download a file.this variable must increment its value.

how can i do this...

for Example
1st time file download with name...

abc_ABC_DDMMYYY1

2nd time
abc_ABC_DDMMYYY2

3rd time
abc_ABC_DDMMYYY3.


so how can i do this?

推荐答案

要声明一个应用程序范围的变量,请在您的app.config文件中声明它

To declare an application wide variable, declare it in you app.config file

<appSettings>
    <!-- Your variable goeas here as under -->
    <add key="your_variable_name" value="your_variable_value"/>
</appSettings>




在代码中获取变量:




To get your variable in code:

string YourVariable= ConfigurationManager.AppSettings["your_variable_name"];



我希望这是您的要求,并且这个答案会有所帮助:)

添加了编辑app.config文件的方式



I hope this is what you were asking and that this answer helps :)

Added way to edit app.config file

// Open App.Config of executable
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Add an Application Setting.
config.AppSettings.Settings.Remove("your_variable_name");
your_variable_new_value = your_variable_value + 1;
config.AppSettings.Settings.Add("your_variable_name", your_variable_new_value);
// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);
// Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings");


来源:如何更改app.config文件在运行时 [


Source: How to change app.config file at runtime[^]


这篇关于我们如何声明应用程序变量.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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