日期:2014-05-18 浏览次数:20872 次
public class MiniHashtable { struct StructNameValue { public Object itemName; public Object itemValue; public void SetValue(Object objName, Object objValue) { itemName = objName; itemValue = objValue; } } private ArrayList m_alNV; public MiniHashtable() { m_alNV = new ArrayList(); } public void Add(Object objName, Object objValue) { StructNameValue snvItem = new StructNameValue(); snvItem.SetValue(objName, objValue); m_alNV.Add(snvItem); } public Object this[Object objName] { get { for (int i = 0; i < m_alNV.Count; i++) { StructNameValue snvItem = (StructNameValue)m_alNV[i]; if (snvItem.itemName.Equals(objName)) return snvItem.itemValue; } return null; } } public Object this[int iIndex] { get { if (iIndex < m_alNV.Count) { StructNameValue snvItem = (StructNameValue)m_alNV[iIndex]; return snvItem.itemValue; } else { return null; } } } public Object Name(int iIndex) { if (iIndex < m_alNV.Count) { StructNameValue snvItem = (StructNameValue)m_alNV[iIndex]; return snvItem.itemName; } else { return null; } } public int Length { get { return m_alNV.Count; } } public void Clear() { m_alNV.Clear(); } }
------解决方案--------------------
1:
string strValue = A.a和i的组合例如(a1,a2...a20);
for(int i=1;i<=20;i++)
string strValue="A.a"+i.toString();
2:
更好的方法,建立一个object型的List或者ArrayList,把你的对象全放进去,
要是知道个数用for循环遍历,如果不知道个数就用foreach实现遍历