Nullable<T>
as T?
CS-R1047Nullable<T>
syntax 49
50 // CS-R1047: Use `T?` instead of `Nullable<T>`.
51 // https://deepsource.io/directory/analyzers/csharp/issues/CS-R1047
52 Nullable<int> i = null; 53
54 // CS-R1024: Use `null-coalescing` operator, i.e. rewrite as `i ?? 1`.
55 // https://deepsource.io/directory/analyzers/csharp/issues/CS-R1024
System.Nullable<T>
indicates that the type T
may be null
. However, the said syntax can be shortened to T?
. This is more concise, readable, and easy to comprehend, especially for programmers coming from languages such as TypeScript.
Nullable<int> i = 0;
int? i = 0;