We have the variable "object value" , which points to a list with one of any type. For example, you can refer to such objects: List<string> or List<Cat> . Which one of them we do not know.
Question: how to create a list of the type we need?
PS1: Googled - to no avail.
PS2: I wrote this code:
Type valueType = value.GetType(); Type listType = valueType.GetGenericArguments()[0]; List<object> instanceList = (List<object>) Activator.CreateInstance(valueType); As a result, a type conversion error is "InvalidCastException" - "InvalidCastException" .
var instanceList = Activator.CreateInstance(valueType);and see what typeinstanceList- Specter