C#循环嵌套的优化,坐等!急急急!!!
本帖最后由 yuanzhouting 于 2013-03-22 12:13:32 编辑
代码如下,dic_add是需要修改到文件里面的内容,hashTable里面是要修改的内容,有时候要修改的东西太多,就会导致速度很慢,而且如果处理的文件很大的话,貌似很占内存,如何处理,使其速度加快,谢谢
private Hashtable addCom(Dictionary<string,string> dic_add,List<string> list_add,Hashtable hashTable)
{
string partreference = string.Empty;
string partNumber = string.Empty;
string temp = string.Empty;
string strtemp = string.Empty;
List<string> alist = new List<string>();
string property = "property";
Func<string,string,bool> lambda = IsContainNum();//此方法是判断是否存在这个字符串的
foreach(KeyValuePair<string,string> item in dic_add)
{
partrefence = item.Key;
partNumber = item.Value;
temp = @"(property PART_NUMBER" +"\r\n"+@"(string"+"\""+partrefence+"\""+"))";
strtemp = "stringDisplay"+"\""+partrefence+"\"";
foreach(object hashItem in new ArrayList(hashTable.Keys))
{
if(hashItem.Equals(partreference))
{
string addtemp = hashTable[hashItem].ToString();
string[] addList = addtemp.Split(new string[]{"\r\n"},StringSplitOptions.RemoveEmptyEntries);
alist.AddRange(addList);
foreach(string str_item in alist)
{
if(lambda(str_item,property))
{
alist.Insert(alist.IndexOf(str_item),temp);
hashTable[hashItem] ="";
foreach(string colTemp in alist)
{
hashTable[hashItem]+= colTemp+"\r\n";
&