Question

I have the following code in my C# application.

DateTimeFormatInfo.CurrentInfo.DayNames

ReSharper 7.1.1 is highlighting the fact that the DateTimeFormatInfo.CurrentInfo could cause a null reference exception.

Under what circumstances would this occur? Or is this just a mistake on ReSharper's part believing that any object whose property you access should be null checked?

Était-ce utile?

La solution

ReSharper is most probably just doing lexical analysis here and nothing deeper.

Since DateTimeFormatInfo is a class, a variable of this type can be null. Which means that the instance returned by DateTimeFormatInfo.CurrentInfo can be a null reference.

That's the error you are getting.

ReSharper doesn't understand that the method was coded such that it will not return a null reference, so it gives a warning.

Don't take the messages from ReSharper as scripture...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top