.NET 2.0 generics - intellisense disagrees with compiler?

R

realgeek

I have tihsl ine of code:
textBox1.Text = string.Join(",",(checkedListBox1.SelectedItems as
IEnumerable).ToArray<string>());

It was composed using intellisense e.g. it told me the method is there,
but when I try to build it it tells me there's no such methods as
ToArray. I tried using no interface cause SelectedItems themselves
contain the method ofc; to no avail.

What am I doing wrong?
 
G

Guest

IEnumerable doesn't contain a definition for ToArray<T>, something like this
should give you the desired results.

string[] selectedValues = (string[])Array.CreateInstance(typeof(string),
this.checkedListBox1.CheckedItems.Count);

((CheckedListBox.CheckedItemCollection)this.checkedListBox1.CheckedItems).CopyTo(selectedValues, 0);
this.textBox1.Text = string.Join(",", selectedValues);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top