List轉字符串,用逗號隔開 List<string> list = new List<string>(); list.Add("a"); list.Add("b"); list.Add("c"); string s = string.Join(",", list.ToArray()); ModuleCodes = request.moduleCodes.IndexOf(',') > 0 ? request.moduleCodes.Split(',').Distinct().ToList() : new List<string> { request.moduleCodes }
list to array:數組
int[] grades = list2.Select(t => t.grade).Distinct().ToArray();
string[] lessons = list2.Select(t => t.lesson).Distinct().ToArray();
list初始化
price.MinPrice = decimal.Parse(selist[0]);網絡
price.MaxPrice = decimal.Parse(selist[1]);less
字符串數組轉int型listide
list添加元素:
string[] productidarray=search.SearchDetail.TempProductId.Split(new string[] { ",", ",", "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); //分割字符串同時去除空格
string TempProductId = string.Join(",", productidarray).Trim().TrimEnd(',') //去除空
string[] inputpids = productIds.IndexOf(',') > 0 ? productIds.Split(',').Distinct().ToArray() : new string[] { productIds }; int[] outputpids = Array.ConvertAll<string, int>(inputpids, delegate(string s) { var val = 0; int.TryParse(s, out val); return val; });
req.ProductIds = outputpids.Where(c=>c>0).ToList(); //string轉int數組
此隨筆或爲本身所寫、或爲轉載於網絡。僅用於我的收集及備忘。code