开发者

const vs new const

No matter what I Google, there doesn't seem to be an answer for this! In a C# class, what does the new keyword do to a const field?

e.g:

private const int ConstOne = 0;
private new co开发者_开发技巧nst int ConstTwo = 0;


The new keyword is used when hiding a member from a base class.
It doesn't actually do anything; it just tells the compiler not to warn you that you're hiding the base field.

See the documentation


The new keyword is used when hiding a member. It works for all class members like methods, fields, etc.

Basically hiding is used to declare that you know that you are going to hide a member and are aware that it is not going to be used in polymorphic scenarios unlike when you are overriding a member.

Google for hiding vs overriding. For example: http://www.akadia.com/services/dotnet_polymorphism.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜