I have to change the username column in my database to nullable, which means everywhere in my code, I now have 开发者_如何学JAVAto check username.HasValue and change references to username to username.Value. Is there anything I can do to avoid having to change all the references to username to username.Value?
Assuming that username
is a string
you don't have to change the type in your code since it's a reference type anyway which can be null or not null. .HasValue
or .Value
don't exist on a reference type. Perhaps you have to make checks like if (username != null)
or if (!string.IsNullOrEmpty(username))
sometimes but that's it.
精彩评论