Reputation: 111
I have a ListBox that contains a System.net.IPAddress
and string items. I want to convert them all to strings. I have tried this as shown below but it says it can not cast from IPAddress to string.
var List4 = f.listBox4.Items.Cast<String>().ToList();
foreach (string i in List4)
{
cursheet.get_Range(colname + x).Value = i;
x++;
}
Upvotes: 0
Views: 158
Reputation: 23113
How about this? No need for linq, casting, etc..
foreach (var item in f.listBox4.Items)
{
cursheet.get_Range(colname + x).Value = item.Text;
x++;
}
Or, if you want the value:
foreach (var item in f.listBox4.Items)
{
cursheet.get_Range(colname + x).Value = item.Value;
x++;
}
Upvotes: 0
Reputation: 16168
var List4 = f.listBox4.Items.Cast<object>().Select(x => x.ToString())
Upvotes: 1