A really boring question, sorry, but I really don’t know that yet 😉 I’ve tried always string.empty, but with a decimal this produces an error.
Is there any function? Unfortunately, for the simplest questions, there are no answers on google
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your title (and tag) asks about an “int”, but your question says that you’re getting an error with a “decimal”. Either way, there is no such thing as “empty” when it comes to a value type (such as an
Integer,Decimal, etc.). They cannot be set toNothingas you could with a reference type (like aStringor class). Instead, value types have an implicit default constructor that automatically initializes your variables of that type to its default value. For numeric values likeIntegerandDecimal, this is 0. For other types, see this table.So you can check to see if a value type has been initialized with the following code:
Note that
mySecondFavoriteNumberis automatically initialized to 0 (the default value for anInteger) behind the scenes by the compiler, so theIfstatement isTrue. In fact, the declaration ofmySecondFavoriteNumberabove is equivalent to the following statement:Of course, as you’ve probably noticed, there’s no way to know whether a person’s favorite number is actually 0, or if they just haven’t specified a favorite number yet. If you truly need a value type that can be set to
Nothing, you could useNullable(Of T), declaring the variable instead as:And checking to see if it has been assigned as follows: