--- 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>`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up