改為
Dictionary<string,?string>?tempDic?=?null;foreach?(var?tempElement?in?xElement.Elements())
{tempDic?=?new?Dictionary<string,?string>();?//加上這行
tempDic.Add(p1_Value,?tempElement.Attribute(p1_Value).Value.ToString());
後面的?tempDic.Clear();這行刪了
List中保存的是對象的引用,妳壹clear,前面加入List中的值就受到影響,最終List中會添加進去n個空的Dictionary(這n個對象指向的都是同壹個tempDic?)
如果妳在循環的外面加壹個比如tempDic.Add("abc",?"123");?那妳List裏就會變成n個同樣的東西