为了账号安全,请及时绑定邮箱和手机立即绑定

C# 怎样定义一个全局都能引用的字符串变量

C# 怎样定义一个全局都能引用的字符串变量

C#
MMMHUHU 2019-06-07 20:06:56
我想定义一个全局都能引用的变量并且在给他赋值之后他的值不会被系统自动删除
查看完整描述

3 回答

?
拉莫斯之舞

TA贡献1820条经验 获得超10个赞

例如:
Common.cs

namespace Common
{
public static class AppInfo
{
public static string AppVersion ="2.1.1";//应用程序版本号
public static string AppCompanyName="公司名称";//公司名称
}
}

app.cs

using System;
using Common;
class Test
{
static void Main()
{
Console.WriteLine("Application Version:{0}",AppInfo.AppVersion);
Console.WriteLine("Application Company name:{0}",AppInfo.AppCompanyName);
}
}

执行命令编译 csc app.cs Common.cs

 


查看完整回答
反对 回复 2019-06-08
?
慕田峪7331174

TA贡献1828条经验 获得超13个赞

建立一个 static 类, 指定一个 static string ,给这个 string 赋值就可以了。

查看完整回答
反对 回复 2019-06-08
  • 3 回答
  • 0 关注
  • 398 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信