c#

位置:IT落伍者 >> c# >> 浏览文章

c#中SortedList的使用


发布日期:2020年09月14日
 
c#中SortedList的使用

对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/> );

}

}

               

上一篇:.NET Remoting 实现分布式数据库查询

下一篇:ado.net快速上手实践篇(一)