Freigeben über


Q & A - What does the new modifier do?

Q: In the Visual Studio Object Browser the method CollectionBase.Clear() is marked as "virtual new." The same happens with other Methods and in other Classes (e.g CollectionBase.GetEnumerator). Opening CollectionBase.Clear with ILDASM it is marked as "virtual final", thus not overridable.

- What exactly is the effect of declaring a methods as "virtual new"?

A: The new modifier applied to a virtual function allows you to explicitly hide a member inherited from a base class hence the “virtual final” in the IL.

From the docs: "To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier."