I am trying to fill object[] with List<string> but I cannot figure out how to use ConvertAll. MSDN did not help me.
At first I tried to create an instance of Converter but it looks like it expects delegate?
Converter<string, object> conv = new Converter<string, object>(??); //why delegate?
this.comboBox1.Items.AddRange(Form1.AnimalType.ConvertAll<object>(conv));
Thanks 🙂
There is no need to convert to object as all types in the .NET runtime inherit from object.
If you want to assign the members of the list
Form1.AnimalTypesto a combobox you should can just add them to theItemscollection and then you should setDisplayMemberto the name of the property you want to display andValueMemberto the name of the property you want to bind.If you want to have just the conversion and the assignment to the combo box does not matter you can do the following:
The converter class is needed for conversions that are not defined by an object’s inheritance, i.e. use converters if you want to convert apples to oranges, but use casts if you want to convert appels or oranges to fruit. In c# 3.0 you can cast a complete collection by using the following snippet:
Using Linq you can also filte the entries of a given type from a collection and then extract a collection of that specific type:
Using Linq you can also use
Selectto do a transformation: