C# join和split

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;
}
 

你可能感兴趣的:(split)