I have a list of string lets say
List<string> mia = new list<string>;
and i am adding data to it from a database
using (SqlCommand command = new SqlCommand("SELECT xyz FROM table",sqlConnection1))
{
sqlConnection1.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
mia.Add(reader["xyz"].ToString());
}
}
sqlConnection1.Close();
}
data is successfully added to it.
combobox.ItemsSource =mia;
even that works fine
But when i try to do
comboOpthol.ItemsSource =mia.Sort();
intellisense throws error Can not implicitly convert type “void” to System.collections.IEnumerable. Why this error is coming. My list have all data then why show it void?
Is there something wrong with way list is defined list?
Because the
Sort()method does not have a return value (it sorts the list in place and returnsvoid). You need to sort first and then assign the list to the item source: