【问题标题】:How to covert IpAddress items to string c#如何将IP地址项目转换为字符串c#
【发布时间】:2012-07-14 16:30:00
【问题描述】:

我有一个包含System.net.IPAddress 和字符串项的列表框。我想将它们全部转换为字符串。我已经尝试过,如下所示,但它说它不能从 IPAddress 转换为字符串。

var List4 = f.listBox4.Items.Cast<String>().ToList();
foreach (string i in List4)
{
    cursheet.get_Range(colname + x).Value = i;
    x++;
}

【问题讨论】:

    标签: c# string linq casting ip-address


    【解决方案1】:
    var List4 = f.listBox4.Items.Cast<object>().Select(x => x.ToString())
    

    【讨论】:

      【解决方案2】:

      这个怎么样?不需要 linq、casting 等。

      foreach (var item in f.listBox4.Items) 
      { 
          cursheet.get_Range(colname + x).Value = item.Text; 
          x++; 
      } 
      

      或者,如果你想要这个值:

      foreach (var item in f.listBox4.Items) 
      {   
          cursheet.get_Range(colname + x).Value = item.Value; 
          x++; 
      } 
      

      【讨论】:

        猜你喜欢
        • 2021-10-15
        • 1970-01-01
        • 1970-01-01
        • 2020-10-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-25
        • 1970-01-01
        相关资源
        最近更新 更多