Cast Object to Generic List

Ich habe 3 generische Typenliste.

List<Contact> = new List<Contact>();
List<Address> = new List<Address>();
List<Document> = new List<Document>();

Und speichern Sie es in einer Variablen mit dem Typ object. Jetzt mache ich keinen Cast Back to List, um einen Foreach durchzuführen, manche davon wie folgt:

List<Contact> = (List<Contact>)obj;

Aber obj Inhalt ändert sich jedes Mal, und ich habe einige davon:

List<???> = (List<???>)obj;

Ich habe eine andere Variable, die den aktuellen Obj hält. Typ:

Type t = typeof(obj);

Kann ich so etwas machen ??:

List<t> = (List<t>)obj;

Obs: Ich habe keinen aktuellen Typ in der Liste, muss ihn aber umwandeln. Stattdessen habe ich jetzt kein anderes Formular:

List<Contact> = new List<Contact>();

Antworten auf die Frage(16)

Ihre Antwort auf die Frage