--- lang: ja-jp breaks: true --- # C# `Nullable<>` 型かどうかの判定 2022-08-05 > 任意の型についてNullableであるかどうか判断する方法 > https://zecl.hatenablog.com/entry/20080105/p1 ```csharp=   public static bool IsNullable(Type type)   {     //クラス(参照型)かどうか     if (type.IsClass)     {       // not Nullable       return false;     }     //ジェネリク型かどうか     if (type.IsGenericType)     {       //ジェネリック型の元となるSystem.Typeオブジェクトを取得し、それがNullable値型であるかどうか       if (type.GetGenericTypeDefinition() == typeof(Nullable<>))       {         // Nullable         return true;       }     }     //いずれでもないなら not Nullable     return false;   } ``` ###### tags: `C#` `Nullable<T>`