CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2007
    Posts
    59

    [RESOLVED] How to get the type of a generic collection?

    Hello,

    instead of trying to explain my question, here a simple example.

    Code:
    List<int> list = new List<int>();
    Type listType = list.GetType();
    
    Type listItemType = listType.GetTypeMagicly(); // <-- This is what I'm trying to get.
    So, I'm trying to get the type used by the list. I know it's probably possible, since I'm able to see it in a string when debugging. I just don't know how to get the typeof(int).

    Thanks in advance.

  2. #2
    Join Date
    Mar 2007
    Posts
    59

    Re: How to get the type of a generic collection?

    After some try and error, I found out the method:

    type.GetGenericArguments()

    Hope it helps someone in the future...

  3. #3
    Join Date
    Mar 2008
    Location
    Atlanta, GA
    Posts
    49

    Re: [RESOLVED] How to get the type of a generic collection?

    Hey thanks, I was wondering this myself a few days ago.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured