Is it possible to somehow transfer the type to a method?

public void блабла( object type) { list<type> NewList = new list<type>() ; } 

Something like that?

    3 answers 3

     public void блабла<T>() { List<T> NewList = new List<T>() ; } 

      In general, every object has an Object.GetType () method that returns the type of this object.

      But try to use strong typing, namely to accept a specific type in methods, and not object.

      • Operator '<' cannot be applied to the type of method 'and' System.Type 'list <type.GetType> - Swear ... - Varyag988
      • @ Varyag988 and why push it into the list? GetType returns Type - this is information about the type and not the type itself. - IAZ
      • Well, I am also. And I would like to have a type inserted there. because This method (with a sheet of which) is used for different types .. Well, I solved the problem a little differently, thank you .. - Varyag988
      • Use mapping. - Nicolas Chabanovsky
      • Clearly extremely ... - Varyag988

      Use the full power of templates .

      • Uh .. Comrade HashCode, why did you correct my message? Also not right. - Andrew Frolov
      • @AndrewFrolov On this service, users communicate in Russian. If your message is not corrected correctly, you can edit it. - Nicolas Chabanovsky
      • Yes, he is often so ... - Varyag988