"新"在C#中的关键字就是制作警告消失了,不是吗? [英] "new" keyword in C# is just for making the warning disappeared, isn't it?

查看:111
本文介绍了"新"在C#中的关键字就是制作警告消失了,不是吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心碰到过这样的网页。 C# - 新的关键字方法签名,我发现,在这个职位给出一些例子是不准确的(比如第二个)

I accidentally come across this page C# - new keyword in method signature and I found that some examples that was given in this post are not accurate (e.g. Second one)

我觉得新,是已经在那里,如果你不 ŧ说覆盖。唯一的区别是,你会得到一个GREENLINE(warrning?),如果你不写任何覆盖(虚拟方式)或新。您仍然可以选择不写新,它仍然可以工作。难道我说错这一点,还是我失去了一些重要的东西?

I think the "new" is already there if you don't say "override". The only difference is that you will get a greenline (warrning?) if you don't write either "override" (for virtual method) or "new". You can still choose not to write "new" and it will still work. Am I right in saying this, or am I missing something important?

推荐答案

是的,它不会做任何事情,除了隐藏的警告

Yes it doesn't do anything except hiding that warning.

警告只是有要确保你知道你在做什么,因为躲在很少是好主意。但要做出覆盖默认会导致版本问题如果基类引入了一个新的虚拟方法和派生类恰好有一个匹配的,但独立的方法,现在意外地覆盖继承的方法

The warning is only there to make sure you know what you're doing, since hiding is rarely a good idea. But making override the default would cause versioning problems if the base class introduces a new virtual method and the derived class happens to have a matching but independent method which now accidentally overrides the inherited method.

这篇关于"新"在C#中的关键字就是制作警告消失了,不是吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆