tagged [overriding]
Can I override a property in c#? How?
Can I override a property in c#? How? I have this Base class: And the following descendant: When I compile I get this warning saying Derived class's definition of `x` is gonna hide Base's version o
- Modified
- 9 Dec at 15:36
Difference between new and override
Difference between new and override Wondering what the difference is between the following: Case 1: Base Class Case 1: Inherited class Case 2: Base Class Case 2: Inherited class Both case 1 and 2 appe...
- Modified
- 7 Jan at 20:51
How does reflection tell me when a property is hiding an inherited member with the 'new' keyword?
How does reflection tell me when a property is hiding an inherited member with the 'new' keyword? So if I have: How can I use reflection to see that ChildClass is hiding the Base implementation of Tem...
- Modified
- 25 Apr at 04:17
The difference between virtual, override, new and sealed override
The difference between virtual, override, new and sealed override I'm pretty confused between some concepts of OOP: `virtual`, `override`, `new` and `sealed override`. Can anyone explain the differenc...
- Modified
- 22 Dec at 10:54
Calling virtual functions inside constructors
Calling virtual functions inside constructors Suppose I have two C++ classes: If I write the following code: One might expect that `n
- Modified
- 9 Jul at 08:7
Why / when would it be appropriate to override ToString?
Why / when would it be appropriate to override ToString? I'm studying C# and I wonder what the point and benefit of overriding `ToString` might be, as shown in the example below. Could this be done in...
- Modified
- 4 May at 23:47
Overriding GetHashCode
Overriding GetHashCode As you know, GetHashCode returns a semi-unique value that can be used to identify an object instance in a collection. As a good practice, it is recommended to override this meth...
- Modified
- 21 Nov at 21:27
How to override default(T) in C#?
How to override default(T) in C#? > [Howto change what Default(T) returns in C#](https://stackoverflow.com/questions/5088682/howto-change-what-defaultt-returns-in-c-sharp) Similarly if I have a cust...
- Modified
- 23 May at 10:29
virtual keyword in c#
virtual keyword in c# I have knowledge of Java and have been learning C# for the last couple of days. Now I have come across the "virtual" keyword which, as suggested at [this link](http://msdn.micros...
- Modified
- 20 May at 20:52
How can I assure a class to have a static property by using interface or abstract?
How can I assure a class to have a static property by using interface or abstract? I have one abstract class -let's say myBase. And I want all the classes derived from myBase to have one static field ...
- Modified
- 14 Mar at 22:44
.net XmlSerializer on overridden properties
.net XmlSerializer on overridden properties I have a base class with an abstract property: now, I have a subclass, which is XmlSerialized. So, it has: I cannot move the XmlElement attribute to basecla...
- Modified
- 16 Jan at 16:13
C#: Any way to skip over one of the base calls in polymorphism?
C#: Any way to skip over one of the base calls in polymorphism? ``` class GrandParent { public virtual void Foo() { ... } } class Parent : GrandParent { public override void Foo() { base.Foo(...
- Modified
- 2 Aug at 14:19
Detect if a method was overridden using Reflection (C#)
Detect if a method was overridden using Reflection (C#) Say I have a base class TestBase where I define a virtual method TestMe() Now I inherit this class: Now, using Reflection, I need to find if the...
- Modified
- 24 Aug at 13:13
Why is it important to override GetHashCode when Equals method is overridden?
Why is it important to override GetHashCode when Equals method is overridden? Given the following class ``` public class Foo { public int FooId { get; set; } public string FooName { get; set; } ...
- Modified
- 4 Jul at 15:37
Can I call a base class's virtual function if I'm overriding it?
Can I call a base class's virtual function if I'm overriding it? Say I have classes `Foo` and `Bar` set up like this: ``` class Foo { public: int x; virtual void printStuff() { std::cout
- Modified
- 8 Jul at 17:39
Why does this work? Method overloading + method overriding + polymorphism
Why does this work? Method overloading + method overriding + polymorphism In the following code: ``` public abstract class MyClass { public abstract bool MyMethod( Database database, AssetDeta...
- Modified
- 2 Dec at 14:31
How to override Equals on a object created by an Entity Data Model?
How to override Equals on a object created by an Entity Data Model? I have an Entity Data Model that I have created, and its pulling in records from a SQLite DB. One of the Tables is People, I want to...
- Modified
- 18 Mar at 18:38
internal abstract methods. Why would anyone have them?
internal abstract methods. Why would anyone have them? I was doing some code review today and came across an old code written by some developer. It goes something like this If you have a derived class...
- Modified
- 25 May at 03:8
I need to access a non-public member (Highlighted Item) of a Combo Box
I need to access a non-public member (Highlighted Item) of a Combo Box I am implementing Key Navigation for an application and I want to override the space key functionality when a Combo Box is focuse...
- Modified
- 17 Feb at 17:0
What is the use of 'abstract override' in C#?
What is the use of 'abstract override' in C#? Just out of curiosity I tried overriding a abstract method in base class, and method the implementation abstract. As below: ``` public abstract class Firs...
- Modified
- 18 Jan at 05:3
Inheritance and Overriding __init__ in python
Inheritance and Overriding __init__ in python I was reading 'Dive Into Python' and in the chapter on classes it gives this example: The author then says that if you want to override the `__init__` met...
- Modified
- 5 May at 16:8
Why does C#/CLR not support method override co/contra-variance?
Why does C#/CLR not support method override co/contra-variance? There are quite a few questions & answers about hacking around the limitation of C# not allowing method return (and argument) types to b...
- Modified
- 7 May at 21:29
Make sure base method gets called in C#
Make sure base method gets called in C# Can I somehow force a derived class to always call the overridden methods base? And then in a derived class : ``` public override void Update() { bas
- Modified
- 31 May at 17:45
Invocation of a polymorphic field-like event
Invocation of a polymorphic field-like event Considering the code below: ``` public class TableMain { public virtual event Action UpdateFilter; .... } public class TableSub : TableMain { public ...
- Modified
- 27 Aug at 07:44
Why would you override wndproc
Why would you override wndproc I have been looking around and haven't really seen much information on why someone would override wndproc to handle messages. So I wondering: I have tried using it when ...
- Modified
- 21 May at 16:29