Visual Studio 2012 does not recognize NULL type

I have 2 DateTimes values โ€‹โ€‹with null values, so subtracting them will nullify the TimeSpan. I want to call .Value on this.

However, the autocomplete drop-down list considers the type inside the brackets to be a regular TimeSpan. .Value not listed, and when I use any suggestions, it does not compile. It compiles when I manually type .Value .

The same problem occurs if only one of the DateTimes is NULL. Does this also happen if I add a TimeSpan? in DateTime? , as a result, we get DateTime? . Intellisense thinks this is a DateTime .

Is this a problem with Visual Studio intellisense? I'm on update 3, I don't have ReSharper. The same problem on another computer.

Edit : To be clear, I ask a question about why intellisense offers the wrong type. I know what to write to compile the code.

+6
source share
1 answer

Agreed, IS gets it wrong and incorrectly concludes that the result of the subtraction is Nullable<TimeSpan> , it passes TimeSpan. You can hit him on the head by writing this as follows:

 var span = date1 - date2; span. 

Now if you type the span variable type correctly, you will see HasValue in the auto-complete window. Otherwise, it does not slow down at runtime, so its a reasonable solution.

We cannot do anything with the original oops, however you can send a feedback report on connect.microsoft.com. Send the link so we can vote for it.

+5
source

Source: https://habr.com/ru/post/949463/


All Articles