© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
16 replies
skyrbunny

❔ Type is Typeof Dictionary

I need to test if a System.Type
t
t
is a Dictionary of any kind, but when I do this check, it doesn't pass it. How do I test for this?
if (t == typeof(Dictionary<,>))
            {
                Debug.Log("Dictionary");
                return $"{{{ConvertType(t.GenericTypeArguments[0])}:{ConvertType(t.GenericTypeArguments[1])}}}";
            }
if (t == typeof(Dictionary<,>))
            {
                Debug.Log("Dictionary");
                return $"{{{ConvertType(t.GenericTypeArguments[0])}:{ConvertType(t.GenericTypeArguments[1])}}}";
            }

I did a log of the type.tostring after and it said
System.Collections.Generic.Dictionary`2[System.String,System.Object]
System.Collections.Generic.Dictionary`2[System.String,System.Object]
so I believe it is indeed a dictionary. Shouldn't it have passed the check?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ typeof()?
C#CC# / help
2y ago
Check if an object is a Dictionary of any type
C#CC# / help
2y ago
❔ Why is typeof(T).FullName a ``string?``, but typeof(T).Name a ``string``
C#CC# / help
3y ago
❔ Cant Find Key Type Byte In Dictionary?
C#CC# / help
3y ago