当前位置:首页 > Windows程序 > 正文

C# join和split

2021-05-25 Windows程序

标签:

string[] parts = { "A", "B", "C", "D", "E" };
string result = string.Join(",", parts);
Console.WriteLine(result);
for (int i = 0; i < result.Split(‘,‘).Length; ++i)
{
    Console.WriteLine(result.Split(‘,‘)[i]);
}
以后拼接json终于不用写if了

放一个看到的找IP4的函数,在存在多个IP4的时候有问题
public string GetIP_4()
{
    string restr = "";
    IPAddress[] ipList = Dns.GetHostAddresses(Dns.GetHostName());
    foreach (IPAddress ip in ipList)
    {
        //获得IPv4                
        if (ip.AddressFamily == AddressFamily.InterNetwork)
        {
            restr = ip.ToString();
            //if (restr.Length >= 9)
            //    break;
        }
    }
    return restr;
}
 

标签:

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/71074.html