Syntax question
-
Hello, I was reading an artical and there was a line of syntax I hadn't seen before and I'm curious what is it doing behind the scenes:
Dim v as single = 2293.22
Dim sh as short = New Short?(v)Short doesn't have a constructor so how did the '?' allow it? Thanks. Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
-
Hello, I was reading an artical and there was a line of syntax I hadn't seen before and I'm curious what is it doing behind the scenes:
Dim v as single = 2293.22
Dim sh as short = New Short?(v)Short doesn't have a constructor so how did the '?' allow it? Thanks. Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
-
Hello, I was reading an artical and there was a line of syntax I hadn't seen before and I'm curious what is it doing behind the scenes:
Dim v as single = 2293.22
Dim sh as short = New Short?(v)Short doesn't have a constructor so how did the '?' allow it? Thanks. Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
That's very interesting. I have never seen that either.
-
See nullable types[^].
-
See nullable types[^].
Erik, Re-looking it, it obviously has something to do with nullable types but do you have any idea why declaring it as nullable allowed a constructor? Thanks, Nathan.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
-
Erik, Re-looking it, it obviously has something to do with nullable types but do you have any idea why declaring it as nullable allowed a constructor? Thanks, Nathan.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
Yes, declaring a variable as Nullable(of T) is the same as using T?, where T would be the underlying value type, so for example:
Dim s as Nullable(Of Short)
Dim s as Short?These two declarations are equivalent. The reason why you can use a constructor is just becouse Nullable(Of T) has one. Replacing Nullable(Of T) with the underlying T? does not change that fact. Here in spain just call it a "syntactical sugar".
-
Yes, declaring a variable as Nullable(of T) is the same as using T?, where T would be the underlying value type, so for example:
Dim s as Nullable(Of Short)
Dim s as Short?These two declarations are equivalent. The reason why you can use a constructor is just becouse Nullable(Of T) has one. Replacing Nullable(Of T) with the underlying T? does not change that fact. Here in spain just call it a "syntactical sugar".