码迷,mamicode.com
首页 > Windows程序 > 详细

C# ConcurrentBag与list

时间:2016-04-03 18:58:40      阅读:1118      评论:0      收藏:0      [点我收藏+]

标签:

 

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个不同的数值

C# ConcurrentBag与list

标签:

原文地址:http://www.cnblogs.com/nashah/p/5350211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!