Finish coding with some warnings at the end could possibly bog down programmers’ confidence.
It may be less or more for each programmer to find that sign of warning.
This short post will suggest the simple example to avoid those warning by using the case when programmers have to reimplement the base’s method which is not explicitly declared as “virtual”.
Consider the following code for our example.
class A { public A() { } public void DoSomething() { System.Console.WriteLine("DoSomething from A"); } } class B: A { public B() { } public void DoSomething() { System.Console.WriteLine("DoSomething from B"); } }
B inherits from A, and B wants to put its own implementation into DoSomething() method. By compiling the above code, the end result will show the warning message like
“Warning 1 … hides inherited member ‘System.Collections.Generic.Dictionary
Although seeing the warning message, we could go along and ignore, but how can we polish all the work done so far, to eliminate those warning message !
As the message says, we use “new” by put it to the beginning of the method signature. This way you just declare yourself that “THIS IS OUR INTENTION!, SO DON’T BOTHER ME AGAIN COMPILER”. :)
class A { public A() { } public void DoSomething() { System.Console.WriteLine("DoSomething from A"); } } class B: A { public B() { } new public void DoSomething() { System.Console.WriteLine("DoSomething from B"); } }
Polishing the code is best, seeing no warning message even they could bite us a little is greater !
Time to polish thing comes everyone.

Like










