C# Get Generic Type Name

前端 未结 9 1747
旧时难觅i
旧时难觅i 2020-11-30 06:09

I need some way to get the Name of a Type, when type.IsGenericType = true.

    Type t = typeof(List);
    MessageBox.         


        
9条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 06:52

    Assuming you just want to see that its List instead of List you'd need to do:

    MessageBox.Show(t.GetGenericTypeDefinition().FullName)
    

    See http://msdn.microsoft.com/en-us/library/system.type.getgenerictypedefinition.aspx

提交回复
热议问题