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?

有帮助吗?

解决方案

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...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top