Skip to main content

Posts

Showing posts with the label .NET tools

Miscellaneous

New Assignment instead of Virtual/Override The "new" keyword can be used with methods, it provides a type of inheritance similar to polymorphism. class Program { static void Main(string[] args) { BaseClass bc = new BaseClass(); ChildClass cc = new ChildClass(); bc.Foo(); bc.Bar(); Console.WriteLine("======================="); ((BaseClass)cc).Foo(); ((BaseClass)cc).Bar(); Console.WriteLine("======================="); cc.Foo(); cc.Bar(); Console.WriteLine("======================="); Console.ReadLine(); } } class BaseClass { public void Foo() { Console.WriteLine("BaseClass.Foo"); } public virtual void Bar() { Console.WriteLine("BaseClass.Bar"); } } class ChildClass : BaseClass { new public void Foo() { ...