|
Hi All,
I am getting following error when I am trying to assign a null value or nuthing value to a variable of type Nullable(Of Decimal).
But for that variable I want to assign a decimal value or null value. The same kind of problem I faced with Nullable (of DateTime) too. It cant take a nothing assigned to it. If it cant take that value then why is it nullable(of Decimal) or Nullable (of DateTime) and System.Nullable(Of Integer) is also not taking null values (means nothing value in VB.Net).
Please help me in resolving this issue.
thanks in advance.
Below is my code: I tried by just putting variable=nothing also but didnt work.
If savRequestData.PropRequestWage IsNot Nothing Then
wagesegment = New List(Of ReqWage)
For Each temp In savRequestData.PropRequestWage
Dim wage As New ReqWage
wage.DailyWage = IIf(Not String.IsNullOrEmpty(temp.DailyWage), IIf(Decimal.TryParse(temp.DailyWage, tempDecimal), tempDecimal, CType(Nothing, System.Nullable(Of Decimal))), CType(Nothing, System.Nullable(Of Decimal)))
wage.RequestId = request_Id
wage.WorkDate = temp.WorkDate
wage.WorkHours = IIf(Not String.IsNullOrEmpty(temp.WorkHours), IIf(Decimal.TryParse(temp.WorkHours, tempDecimal), tempDecimal, CType(Nothing, System.Nullable(Of Decimal))), CType(Nothing, System.Nullable(Of Decimal)))
wagesegment.Add(wage)
requestedamount += IIf(temp.DailyWage IsNot Nothing, temp.DailyWage, 0)
Next
End If
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Sub Main()
Dim d As Nullable(Of Integer)
d = Nothing
Console.WriteLine("d=", d)
Console.ReadKey()
End Sub
Works fine for me. However, the line
wage.WorkHours = IIf(Not String.IsNullOrEmpty(temp.WorkHours), IIf(Decimal.TryParse(temp.WorkHours, tempDecimal), tempDecimal, CType(Nothing, System.Nullable(Of Decimal))), CType(Nothing, System.Nullable(Of Decimal)))
..is something I'd delete during a code-review. It's doing to much on a single line, making debugging harder. It's not C++, and there's no shame in using a line per statement.
|
|
|
|