标签:
ConcurrentBag<T>与List<T>
我遇到的一个情况是:
using System.Collections.Concurrent;
class WX
{
public string wxNo;
public string wxPsw;
}
static public bool ReadWechatIds(string path,out ConcurrentBag<WX> list)
{
list = new ConcurrentBag<WX>();
string[] wechatlist = File.ReadAllLines(path);
string []seperator={"--"};
//WX wx = new WX();
foreach(string i in wechatlist)
{
string[] wechatid = i.Split(seperator,StringSplitOptions.RemoveEmptyEntries);
WX wx = new WX();
wx.wxNo = wechatid[0];
wx.wxPsw = wechatid[1];
list.Add(wx);
}
if (list!= null)
return true;
else
return false;
}
比如 wechalist里有100个不一样的数值,如果把注释掉的东西写到外面,会出现100个相同的数值
这是这种集合ConcurrentBag的特性
如果换成list<T>
static public bool ReadWechatIds1(string path, out List<WX> list)
{
list = new List<WX>();
string[] wechatlist = File.ReadAllLines(path);
string[] seperator = { "--" };
//WX wx = new WX();
foreach (string i in wechatlist)
{
string[] wechatid = i.Split(seperator, StringSplitOptions.RemoveEmptyEntries);
WX wx = new WX();
wx.wxNo = wechatid[0];
wx.wxPsw = wechatid[1];
list.Add(wx);
}
if (list != null)
return true;
else
return false;
}
wechalist里有100个不一样的数值,如果把注释掉的东西写到外面,会出现100个不同的数值
标签:
原文地址:http://www.cnblogs.com/nashah/p/5350211.html