In VS2010 for a VB.NET 4.0 project, the IDE puts a green line under the last line in the following code:
Dim cityLocal As DateTime
cityLocal = externalFunction()
cityLocal.Today()
The suggested code replace is to update ‘cityLocal’ with ‘Date’. The reason is:
Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
But it does compile and does work correctly. Is this just a bug in the VS2010?
Today is a shared member, thus should not (but can) be accessed through an instance of DateTime change your code to.
DateTime.TodayAlthough Visual Studio gives you suggestions to correct the “Error” it is infact a compiler warning, warning you that there is no need for an instance to access the shared member. You’ll find that it is not listed as an error in the error list. Which is why it compiles correctly.
The Visual Basic language specification states
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=01EEE123-F68C-4227-9274-97A13D7CB433:
More information on the warning can be found in the documentation.
http://msdn.microsoft.com/en-us/library/y6t76186.aspx