warning on accessing shared method

G

Guest

Why do I get a warning:
Access of shared member, constant member, enum member or nested type through
an instance; qualifying expression will not be evaluated

When accessing a shared method in the framework. (for example)
If Control.MouseButtons = MouseButtons.None Then....

What is the point of includes if they don't prevent this type of warning?
Will I always need to explicitly specify the name space?
If Control.MouseButtons = Windows.Forms.MouseButtons.None Then .....


Thanks for any insight into this!
 
J

Jon Skeet [C# MVP]

iamahulk said:
Why do I get a warning:
Access of shared member, constant member, enum member or nested type through
an instance; qualifying expression will not be evaluated

When accessing a shared method in the framework. (for example)
If Control.MouseButtons = MouseButtons.None Then....

What is the point of includes if they don't prevent this type of warning?
Will I always need to explicitly specify the name space?
If Control.MouseButtons = Windows.Forms.MouseButtons.None Then .....

This is only because MouseButtons is the name of a property as well as
a type. If MouseButtons weren't a property in the current class you're
writing the code in, it would be absolutely fine. For instance, you
could write the above in a class which didn't derive from anything
other System.Object and it would be fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top