对IDictionary进行操作是发现用SortedList也可以等同于 ArryList和Hashtable的结合只是通过Key排序key不允许为空和null
value可以在效率上没有测试但是保证是低必定在插入时要比较排序
通过公用方法得到信息(得到行数据)
public IDictionary ExecuteDictionary( IDbCommand iCmd )
{
IDataReader reader = null;
try
{
//只读取一行数据第一行
reader = iCmdExecuteReader( CommandBehaviorSingleRow );
}
catch(Exception e)
{
thisClose( iCmd );
return null;
}
IDictionary dict = null;
if(readerRead())
{
int fieldCount = readerFieldCount;
dict = new SortedList( fieldCount );
for(int i = ; i < fieldCount; i++)
{
dict [readerGetName( i )ToLower()] = readerGetValue( i );
}
}
readerClose();
readerDispose();
return dict;
}
//返回list
public SortedList selectSingln()
{
DBCommandText = @ SELECT TOP * FROM products;
DBCommandType = CommandTypeText;
return (SortedList)DBExecuteDictionary();
}
//遍历list
private void _BeginRun()
{
_SqlServerLogic logic = new _SqlServerLogic();
SortedList dic = logicselectSingln();
Hashtable hash = new Hashtable();
//遍历sortlist
foreach(DictionaryEntry entry in dic)
{
ResponseWrite( entryKey + *** + entryValue + <br> );
if( !stringIsNullOrEmpty( entryValueToString() ) )
{
hashAdd( entryKey entryValue );
}
}
IDictionaryEnumerator item = hashGetEnumerator();
//遍历Hashtable
while( itemMoveNext() )
{
ResponseWrite( itemKey ++ itemValue +<br/> );
}
string [] ary = new string [dicCount];
dicKeysCopyTo( ary );
ResponseWrite( stringJoin( ary ) );
//for 遍历list
for(int i = ; i < dicCount; i++)
{
ResponseWrite( dicGetKey(i)++ dicGetByIndex(i) +<br/> );
}
}