如果静态变量是整型数值,可以使用枚举,如:public enum Color { Red = 0, Yellow = 1, Blue = 2 }如果不是整数,那么使用一个类定义,也可以的。(专门写个静态的实体类) public class Message { public static const string M0010 = "数据库连接失败"; public static const string M0020 = "非法数据"; //...}
怎样给ArrayList 添加10个静态变量 ~~~~~动态的加~~~~ 例如: public static i1=1 然后动态的生成 public startic i2 =2 到10
我想取i2的值,就去i2的值 ===========================================================================你这样用数组或ArrayList就可以了撒... ArrayList NumberList = new ArrayList(); private const int UBound = 10;for(int i=1; i<=UBound; i++) { NumberList.Add(i); }//使用: int num = (int)NumberList[1]; // num = 1
你可以在ArrayList.Add()中加入二维对象,一个放变量名,一个放值 是这样吗? public class mItem:IComparable { private string name,text; public string Name { get{return name;} set{name=value;} } public string Text { get{return text;} set{text=value;} } public override string ToString() {...} public int CompareTo(object obj) {...} ... 然后在你的ArrayList中加这样的对象好了: ArrayList al=new ArrayList(); al.Clear(); foreach(Control cl in this.Controls) { mItem it=new mItem(cl.Name,cl.Text); al.Add(it); } cbo.DataSource=al; 这样你只要对mItem判断就行了,要取哪个就哪个,不知道行不行
什么意思?
~~~~~动态的加~~~~
例如: public static i1=1 然后动态的生成 public startic i2 =2 到10
我想取i2的值,就去i2的值
{
Red = 0,
Yellow = 1,
Blue = 2
}如果不是整数,那么使用一个类定义,也可以的。(专门写个静态的实体类)
public class Message
{
public static const string M0010 = "数据库连接失败";
public static const string M0020 = "非法数据";
//...}
~~~~~动态的加~~~~
例如: public static i1=1 然后动态的生成 public startic i2 =2 到10
我想取i2的值,就去i2的值
===========================================================================你这样用数组或ArrayList就可以了撒...
ArrayList NumberList = new ArrayList();
private const int UBound = 10;for(int i=1; i<=UBound; i++)
{
NumberList.Add(i);
}//使用:
int num = (int)NumberList[1]; // num = 1
是这样吗?
public class mItem:IComparable
{
private string name,text;
public string Name
{
get{return name;}
set{name=value;}
}
public string Text
{
get{return text;}
set{text=value;}
}
public override string ToString()
{...}
public int CompareTo(object obj)
{...}
...
然后在你的ArrayList中加这样的对象好了:
ArrayList al=new ArrayList();
al.Clear();
foreach(Control cl in this.Controls)
{
mItem it=new mItem(cl.Name,cl.Text);
al.Add(it);
}
cbo.DataSource=al;
这样你只要对mItem判断就行了,要取哪个就哪个,不知道行不行