Oliver Dixon Oliver Dixon - 1 year ago 95
C# Question

C# and nullable flag/annotation?

Does C# have Nullable annotation's?

For example in Java

public @Nullable <T extends BaseJsonClass> T getModel(String saveKey, Class<T> type) {

Now when the developer tries to call


The compiler will warn them that they are not checking for null.

I'm aware of the
mark at the end of var names in C# like
but the problem with this is that it can be tricky/annoying/JSON models when vars are being used in many places.

Answer Source

C# does not have anything like that - such feature is not a part of the language (yet).

However, if you use Resharper, you can utilize its Value and Nullability Analysis feature, which allows you to add several attributes to your code: [CanBeNull], [NotNull], [ItemCanBeNull], [ItemNotNull]. The nullability analysis performed by the plugin will take these attributes into account, resulting in the compile-time warnings you ask for.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download