你真的是指非通用的Hashtable吗?您可以使用LINQ,假设您可以使用:
string keys = string.Join(",", table.Keys.Cast<object>()
.Select(x => x.ToString())
.ToArray());
Run Code Online (Sandbox Code Playgroud)
可能有更快的方法,但这就是我为了可读性而采取的方式.当你证明它是一个瓶颈时,只有微优化.
您还可以使用IDictionaryEnumerator:
IDictionaryEnumerator enum = table.GetEnumerator();
while (enum.MoveNext())
{
text += enum.Key + ", ";
text += enum.Value + "\n";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8356 次 |
| 最近记录: |