Class.cs里写个全局的动态字符串数组

xxxx_love 2009-03-14 07:16:08
在Class.cs类里 我想写个string[] 数组 在运行时主程序 初始化它 然后作为全局变量可以调用它 请教 呵呵
...全文
61 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxxx_love 2009-03-14
  • 打赏
  • 举报
回复

class Class1
{
public int[] myArray = new int[100];
public int this[int index]
{
get
{
if (index < 0 || index >= 100)
return 0;
else
return myArray[index];
}
set
{
if (!(index < 0 || index >= 100))
myArray[index] = value;
}
}
}

主要是受这个影响 现在还没明白 上面的来龙去脉 看谁能解释下

9楼的是对的

class Class1
{
public static string[] a =null;
}



wuyi8808 2009-03-14
  • 打赏
  • 举报
回复
class Class1
{
public static string[] a;
}

class Program
{
static void Main()
{
Class1.a = 从数据库中读入;
}
}
xxxx_love 2009-03-14
  • 打赏
  • 举报
回复
我的要求是写在 calss1.cs类 里面 可能没说清楚

登录成功后 用数据库首先添充他 以后再调用里面的数据 就不会在读数据库

其长度是不确定的
accomp 2009-03-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyi8808 的回复:]
C# codeclass Program
{
public static string[] a;

static void Main()
{
a = new string[] { "abc", "123", "其他", };
}
}
[/Quote]
这个
changjiangzhibin 2009-03-14
  • 打赏
  • 举报
回复
定义成全局的静态的即可,可使用一个全局的类
xxxx_love 2009-03-14
  • 打赏
  • 举报
回复
呵呵 具体点
wuyi8808 2009-03-14
  • 打赏
  • 举报
回复
class Program
{
public static string[] a;

static void Main()
{
a = new string[] { "abc", "123", "其他", };
}
}
aa37742698 2009-03-14
  • 打赏
  • 举报
回复
写成共有的属性就可以了吧
wuyi8808 2009-03-14
  • 打赏
  • 举报
回复
public static string[] a;
xxxx_love 2009-03-14
  • 打赏
  • 举报
回复
ding

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧