Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating nullable data types in c#

Tags:

c#

nullable

I have a data type called

public enum Gender { Male, Female }

But some case i need to pass the vale for the gender as empty. So how can i create nullable Gender in C#

like image 859
samadhi Avatar asked Apr 17 '26 23:04

samadhi


1 Answers

Either

Gender? myGender = null;

Or

Nullable<Gender> myGender = null;

The first variant is exactly the same as the second, but it just C# syntactic sugar to ease the readability of nullable variables.

like image 73
Øyvind Bråthen Avatar answered Apr 19 '26 12:04

Øyvind Bråthen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!