1,根据Hashtable的key 修改相应value的问题
问题描述
public Hashtable favoriteHashTableFolder = new Hashtable();
favoriteHashTableFolder.put( "1","a");
favoriteHashTableFolder.put( "2","b");
favoriteHashTableFolder.put( "3","c");
现在我想把key为3的值"c"变为"cc",请问该怎么做? <script type="text/javascript"></script>
解决方法:
favoriteHashTableFolder.put( "3","cc");
直接覆盖吧!
2,在网络上接受数据的时候,会接受来自同一客户端的数据,他们的IP和端口号是固定的。此时,如果将ip+port作为Key,接收的内容作为value,则需要在已存在的key 中追加value.
Hashtable content = new Hashtable();
if (Content.ContainsKey(state.workSocket.LocalEndPoint.ToString()))
{
Content[state.workSocket.LocalEndPoint.ToString()] += PrintTemp;
}
else
{
Content.Add(state.workSocket.LocalEndPoint.ToString(), PrintTemp);
}
}
说明:PrintTemp为网络接收数据。