Cannot implicitly convert type 'string' to 'System.Collections.Generic.List<string>'
c#, list, string
Solution
This is the problematic line:
List<string> listString = listObject.OrderBy(x => x.m_Type).ToString();
`ToString` returns a string, and you're trying to assign to a `List<string>` variable.
You need to do something like this:
List<string> listString = listObject.OrderBy(x => x.m_Type)
.Select(x => x.ToString())
.ToList();
This statement will order your `listObject` enumerable to the order that your want, then convert the values to strings, and finally convert the enumerable to a `List<string>`.
Problem
This question has probably been answered hundreds of times, but here goes. I have this chunck of code: ``` private void PopulateStringDropdownList(List<ObjectInfo> listObject, object selectedType = null) { List<string> listString = listObject.OrderBy(x => x.m_Type).ToString(); for (int i = 0; i < listString .Count; i++) { for (int j = i + 1; j < listString .Count; j++) { if (String.Equals(listString [i], listString [j])) { listString.RemoveAt(j); } } } ViewBag.property1 = new SelectList(listString ); } ``` So basically I'm trying to populate a dropdown List with strings coming from a property of each objects contained in the list I pass in parameter. But the code doesn't compile because of the error you're seeing up there, and I've yet to understand why exactly. Any help anyone?