求动态数组实例 我需要用一个二维的动态数组,谁能给个实例参照一下,包括创建,添加记录,遍历数组,数组的生命周期是页面内,WinForm的急用,谢谢大家了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用的是1.1,所以list用不了~~ (1)定义一个结构或类即可搞定。public class abc{ public List<object> obj1 = new List<object>(); public List<object> obj2 = new List<object>();}创建,添加记录,遍历数组应该自己可以搞定吧。 你还用VS2003呵。你可以用下面一维的改写成二维的。 private void SubReDim(ref int[] List, bool IsIncrease) { // int iCount = 0; try { if (List == null || List.Length == 0) { int[] tmpList = new int[1]; List = tmpList; } else { if (IsIncrease) { iCount = List.Length; int[] tmpList = new int[iCount + 1]; Array.Copy(List, tmpList, List.Length); List = tmpList; } else { iCount = List.Length - 1; int[] tmpList = new int[iCount + 1]; Array.Copy(List, tmpList, tmpList.Length); List = tmpList; } } } catch (Exception ex) { MessageBox.Show(ex.Message.Trim(), "SubReDim Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } object [,] a = new object[m, n]; class DTClass { private string tabName; private string selString; public DTClass(string name, string strSQL) { this.tabName = name; this.selString = strSQL; } public string Name { get { return tabName; } set { tabName = value; } } public string SelString { get { return selString; } set { selString = value; } } } class DTClassIndexer //索引器, 用于对 DTClass 进行操作 { private ArrayList arrDTClass; public DTClassIndexer() { arrDTClass = new ArrayList(); } //声明一个索引器 public string this[string name] { get { foreach (DTClass cs in arrDTClass) { if (cs.Name == name) { return cs.SelString; } } return string.Empty; } set { arrDTClass.Add(new DTClass(name, value)); //调用: arr["ss"]="asdfasfa"; } } public int Count() //返回长度 { return arrDTClass.Count; } } static void Main() { ds["ss"] = "sss"; Console.WriteLine(ds.Count()); ds["sss"] = "sssss"; Console.WriteLine(ds.Count()); } c# 操作图片 关于序列化和反序列化 如何判断是否用DES加密 C#传递结构体给C++写的Dll 如何遍历下拉菜单? 为什么string转化为double或float原来的1.34变化为1.34000000001了呢? C#与ORACLE数据库的连接 C#简单入门问题 其他信息: 未将对象引用设置到对象的实例。帮忙看看问题出在哪里 谁能给我一段登陆的代码啊C# 如果能用存储过程更好 为什么我控制其他窗体控件,没反应? c#中的惊天大错误,紧急求救
public class abc
{
public List<object> obj1 = new List<object>();
public List<object> obj2 = new List<object>();
}
创建,添加记录,遍历数组应该自己可以搞定吧。
private void SubReDim(ref int[] List, bool IsIncrease)
{
//
int iCount = 0; try
{
if (List == null || List.Length == 0)
{
int[] tmpList = new int[1];
List = tmpList;
}
else
{
if (IsIncrease)
{
iCount = List.Length;
int[] tmpList = new int[iCount + 1];
Array.Copy(List, tmpList, List.Length);
List = tmpList;
}
else
{
iCount = List.Length - 1;
int[] tmpList = new int[iCount + 1];
Array.Copy(List, tmpList, tmpList.Length);
List = tmpList;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.Trim(), "SubReDim Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
{
private string tabName;
private string selString; public DTClass(string name, string strSQL)
{
this.tabName = name;
this.selString = strSQL;
} public string Name
{
get { return tabName; }
set { tabName = value; }
} public string SelString
{
get { return selString; }
set { selString = value; }
}
} class DTClassIndexer //索引器, 用于对 DTClass 进行操作
{
private ArrayList arrDTClass;
public DTClassIndexer()
{
arrDTClass = new ArrayList();
} //声明一个索引器
public string this[string name]
{
get
{
foreach (DTClass cs in arrDTClass)
{
if (cs.Name == name)
{
return cs.SelString;
}
}
return string.Empty;
}
set
{
arrDTClass.Add(new DTClass(name, value)); //调用: arr["ss"]="asdfasfa";
}
} public int Count() //返回长度
{
return arrDTClass.Count;
}
} static void Main()
{
ds["ss"] = "sss";
Console.WriteLine(ds.Count());
ds["sss"] = "sssss";
Console.WriteLine(ds.Count());
}