convert 'String' to 'System.Collections.ICollection'

SIMIN

Regular
Joined
Mar 10, 2008
Messages
92
Hi,

A component I use needs a collection to be added to it.
I get a list from user in a multi line text box.
So how can I add it?
The list is multi line but is string and object needs collection.
So when I use this:

ThirdPartyObject.List.AddRange(ListTextBoxX.Text)

Warning 1 Runtime errors might occur when converting 'String' to 'System.Collections.ICollection'.
 
In your case PD's idea to use the .Lines property is probably ideal.

If for some reason you have similar data; but not in a TextBox control, you could try code like the following:

C#:
// some delimited string
String text = "Some Text, Line Two, Line Three";
// split text by delim save array result
// define this as an array (the code tags are making my square brakets show up wrong)
String sItems = text.Split(',');

// add each item to the list
foreach (String item in sItems)
{
    If(item != String.Empty)
        ThirdPartyObject.List.Add(item);
}
 
Back
Top