关于List的一些操作
List<string>元素被单引号包裹:
string.Concat("'", string.Join("','", myLis.ToArray()), "'");
string.Join(",", myLis.Select(x => "'" + x + "'").ToArray());
取list的前多少行:
(from a in keyWordList orderby a.Total descending select a).Take(30).ToList();
List<string> 转List<decimal>
List<decimal> temp = odvalues.ConvertAll<decimal>(delegate (string x) {
return Convert.ToDecimal(x);
});
浅复制:
- List< T > oldList = new List< T >();
- oldList.Add(..);
- List< T > newList = oldList;
深复制:
- List< T > oldList = new List< T >();
- oldList.Add(..);
- List< T > newList = new List< T >(oldList);
也可以用序列化反序列化的方法实现深度复制