Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将IpAddress项转换为字符串c#_C#_String_Linq_Casting_Ip Address - Fatal编程技术网

如何将IpAddress项转换为字符串c#

如何将IpAddress项转换为字符串c#,c#,string,linq,casting,ip-address,C#,String,Linq,Casting,Ip Address,我有一个列表框,其中包含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++; } var List4=f.li

我有一个列表框,其中包含
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++;
}
var List4=f.listBox4.Items.Cast().ToList();
foreach(列表4中的字符串i)
{
cursheet.get_范围(colname+x).Value=i;
x++;
}
var List4=f.listBox4.Items.Cast()。选择(x=>x.ToString())

这个怎么样?无需linq、铸造等

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++; 
} 
foreach (var item in f.listBox4.Items) 
{   
    cursheet.get_Range(colname + x).Value = item.Value; 
    x++; 
}