有时候会出现需要将一个集合分成所干个集合,依次再对每组集合进行处理,想了想,用 Linq 处理就很方便
var times = Math.Ceiling((double)lis.Count() / 40);
var temp1 = lis.Skip(0).Take(40); //第一组
var temp2 = lis.Skip(40).Take(40); //第二组
for (int i = 0; i < times; i++)
{
//每一组
var ary = lis.Skip(i * 40).Take(40);
//处理每小组数据
}
知识兔对于Web程序而言,一般情况需要的一些设备字段之类的往往是写在config 配置文件中,通过 ConfigurationManager.AppSettings["XXX"]读取,这样使用无可厚非,现在接触的一些项目都是要求尽量写在xml 文件中去配置,两种方式,殊途同归。
比如新建一xml 文件,将对应数据配置到XML中后,然后通过Linq to xml 进行读取操作,不怎么高大上
//将 XML中值写入到字典中
public Dictionary<string, string> GetValue()
{
Dictionary<string, string> des = new Dictionary<string, string>();
try
{
var exePath = AppDomain.CurrentDomain.BaseDirectory.ToString();
string Path = exePath + "APIConfig" + "\\APIConfig.xml";
XElement root = XElement.Load(Path);
var quests = from c in root.Elements() select c;
foreach (var item in quests)
{
des.Add(item.Name.LocalName, item.Value);
}
return des;
}
catch (Exception ex)
{
Log.LogHelper.LogQueue.Enqueue(ex.Message + "--" + ex.StackTrace);
return des;
}
}
知识兔拿到字典值后,给字段对应赋值即可