winform添加Arraylist类型的全局变量

lulubooboo 2010-09-02 02:28:44
大家好,我想在winform中添加一个Arraylist类型的全局变量,应该咋样定义呀?
...全文
209 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lulubooboo 2010-09-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 peter200694013 的回复:]
引用 8 楼 lulubooboo 的回复:
引用 4 楼 peter200694013 的回复:
引用 3 楼 lulubooboo 的回复:
引用 1 楼 peter200694013 的回复:
http://www.javaeye.com/topic/146362


public class GlobalVariant
{
private static ArrayList……
[/Quote]

请问如果在新的地方对这个GlobalVariant.RightLis进行实例化?
Peter200694013 2010-09-02
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lulubooboo 的回复:]
引用 4 楼 peter200694013 的回复:
引用 3 楼 lulubooboo 的回复:
引用 1 楼 peter200694013 的回复:
http://www.javaeye.com/topic/146362


public class GlobalVariant
{
private static ArrayList m_rightList = new Array……
[/Quote]

public class GlobalVariant
{
public static ArrayList m_rightList = new ArrayList();
}

static void Main(string[] args)
{


GlobalVariant.m_rightList.Add("1");
Console.WriteLine(GlobalVariant.m_rightList[0]);
}
lulubooboo 2010-09-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 peter200694013 的回复:]
引用 3 楼 lulubooboo 的回复:
引用 1 楼 peter200694013 的回复:
http://www.javaeye.com/topic/146362


public class GlobalVariant
{
private static ArrayList m_rightList = new ArrayList();

public static str……
[/Quote]

ArrayList rightList = (ArrayList)GlobalVariant.RightList;为什么会报错呢?
lulubooboo 2010-09-02
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wuyq11 的回复:]
public Arraylist list
{
get;set;
}
[/Quote]

这样使用ArrayList rightList = (ArrayList)GlobalVariant.RightList;不正确吗?
wuyq11 2010-09-02
  • 打赏
  • 举报
回复
public Arraylist list
{
get;set;
}
gohappy2008 2010-09-02
  • 打赏
  • 举报
回复
public partial class Form1 : Form
{
public ArrayList List = null; //全局变量

public Form1()
{}
}
Peter200694013 2010-09-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lulubooboo 的回复:]
引用 1 楼 peter200694013 的回复:
http://www.javaeye.com/topic/146362


public class GlobalVariant
{
private static ArrayList m_rightList = new ArrayList();

public static string RightList///这个……
[/Quote]
public class GlobalVariant
{
public static ArrayList m_rightList = new ArrayList();
}
直接这么写,试试

使用
GlobalVariant.m_rightList

//如果类型一样,使用泛型List<T>吧
lulubooboo 2010-09-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 peter200694013 的回复:]
http://www.javaeye.com/topic/146362
[/Quote]

public class GlobalVariant
{
private static ArrayList m_rightList = new ArrayList();

public static string RightList///这个总是不对啊,应该怎么写呢

{
get
{
return m_rightList;
}
set
{
m_rightList = value;
}
}
}
q107770540 2010-09-02
  • 打赏
  • 举报
回复
public partial class Form1 : Form
{
public Arraylist ay; //
   public Form1()
{
}
}
Peter200694013 2010-09-02
  • 打赏
  • 举报
回复

110,534

社区成员

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

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

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