SomeType?
is syntactic sugar for Nullable<SomeType>
. It can only be applied to value types (not reference types) and indicates that the variable will also be able to store a value equivalent to what null
is for reference types. (Value types cannot be null, so the Nullable<T>
type was added to allow for such cases. It's extremely useful in database binding code, where nullable columns are common.)
using (SomeType x = y) { ... }
is syntactic sugar for:
SomeType x = y;
try {
...
} finally {
if (x != null)
((IDisposable)x).Dispose();
}
This pattern is common when using objects whose classes implement IDisposable, as a way to automatically clean up such objects when they are about to fall out of use.