如题!我以前的时候会这样写
private ArrayList arr= ArrayList.Synchronized(new ArrayList());
现在换成
private List<string> list = new List<string>();
是线程安全的吗?还有
private Hashtable HTTcpCar = Hashtable.Synchronized(new Hashtable());
现在换成
Dictionary<string, ClientState> d = new Dictionary<string, ClientState>();
是线程安全的吗?如果不是,我用泛型的时候怎么实现线程安全?
private ArrayList arr= ArrayList.Synchronized(new ArrayList());
现在换成
private List<string> list = new List<string>();
是线程安全的吗?还有
private Hashtable HTTcpCar = Hashtable.Synchronized(new Hashtable());
现在换成
Dictionary<string, ClientState> d = new Dictionary<string, ClientState>();
是线程安全的吗?如果不是,我用泛型的时候怎么实现线程安全?
如果不是,怎么办?
如果我写成 public class MyArrayList<ItemType> : ArrayList
{
ArrayList Items = ArrayList.Synchronized(new ArrayList()); public void Add(ItemType item)
{
Items.Add(item);
} public void RemoveAt(int index)
{
Items.RemoveAt(index);
} public ItemType GetItem(int index)
{
return (ItemType)Items[index];
} } 是否就是线程安全的了呢,如果这样写,是否还具有泛型不拆箱装箱的特性呢?