zoukankan      html  css  js  c++  java
  • 字符串与List互转

    List转字符串,用逗号隔开

    List<string> list = new List<string>(); list.Add("a"); list.Add("b"); list.Add("c"); //MessageBox.Show(list.); //LoadModel(); string s = string.Join(",", list.ToArray()); MessageBox.Show(s);

    List<test> list = new List<test>(); list.Add(new test("1", "a")); list.Add(new test("2", "b")); list.Add(new test("", "")); list.Add(new test("3", "c")); var a = from o in list select o.test1; var b = from o in list select o.test2; string s1 = string.Join(",", a.ToArray()); string s2 = string.Join(",", b.ToArray()); MessageBox.Show(s1 + " " + s2);

    结果:1,2,,3

          a,b,,c

    字符串转List

    这里s的分隔符不是“,”而是“, ”,后面有一个空格

    string s = "1, 2, 3"; List<string> list = new List<string>(s.Split(new string[] { ", " },

    StringSplitOptions.RemoveEmptyEntries)); foreach (string t in list) {     MessageBox.Show("*" + t + "*"); }

    这里s的分隔符是“,”

    string s = "1,2,3"; List<string> list = new List<string>(s.Split(',')); foreach (string t in list) {     MessageBox.Show("*" + t + "*"); }

    }

  • 相关阅读:
    单向绑定和双向绑定
    Vue
    事件处理
    网关
    同时加载多个配置集
    Nacos Group方案
    DataID方案
    maven_provided说明
    C#大数据导入-SqlBulkCopy
    https://webyog.com/product/monyog/
  • 原文地址:https://www.cnblogs.com/dzhf/p/7605821.html
Copyright © 2011-2022 走看看