Click here to Skip to main content
15,897,187 members
Home / Discussions / C#
   

C#

 
AnswerRe: backup and restore Pin
Harvey Saayman15-Sep-09 23:52
Harvey Saayman15-Sep-09 23:52 
AnswerRe: backup and restore Pin
Christian Graus16-Sep-09 1:30
protectorChristian Graus16-Sep-09 1:30 
QuestionInheritance Problem. Can I do this? Pin
TheFoZ15-Sep-09 23:13
TheFoZ15-Sep-09 23:13 
AnswerRe: Inheritance Problem. Can I do this? Pin
dojohansen15-Sep-09 23:35
dojohansen15-Sep-09 23:35 
GeneralRe: Inheritance Problem. Can I do this? Pin
TheFoZ16-Sep-09 1:49
TheFoZ16-Sep-09 1:49 
GeneralRe: Inheritance Problem. Can I do this? Pin
dojohansen16-Sep-09 2:06
dojohansen16-Sep-09 2:06 
AnswerRe: Inheritance Problem. Can I do this? Pin
TheFoZ16-Sep-09 2:08
TheFoZ16-Sep-09 2:08 
GeneralRe: Inheritance Problem. Can I do this? Pin
dojohansen16-Sep-09 3:33
dojohansen16-Sep-09 3:33 
No, you don't need "new". You need "override". The "new" keyword is for member *hiding*, not overriding.

To understand why, you need to know about the difference between virtual and non-virtual members, also often described as "late-bound" and "early-bound" members. It's also helpful to understand the concepts of reference types and value types.

A couple resources I dug up for you quickly (you may want to google for others if they don't work for you):

Value Types vs Reference Types[^]

Virtual Members vs Non-Virtual[^]

Or google "polymorphism" and these other terms I've mentioned.

In brief, virtual members work as follows: When a member is accessed, such as method Foo(), the implementation of that method is resolved ("bound") at run-time, based on the run-time (actual) type of the object. For non-virtual members, the implementation is resolved at compile time (when you compile), based on the declared type of the reference.

For example:

public class A
{
virtual public string Foo() { return "A.Foo()"; }
}

public class B : A
{
override public string Foo() { return "B.Foo()"; }
}

void test()
{
A obj = new A();
MessageBox.Show(obj.Foo()); // "A.Foo()"

obj = new B();
// Now, "obj" is still of declared type "A", but run-time type "B".
MessageBox.Show(obj.Foo()); // "B.Foo()"
}


If instead you declared A.Foo without the virtual keyword and used new to hide this method in B, the second call to "obj.Foo" would still resolve to A.Foo, because obj is of declared type A.
GeneralRe: Inheritance Problem. Can I do this? Pin
TheFoZ16-Sep-09 3:50
TheFoZ16-Sep-09 3:50 
QuestionC# program deployment issue Pin
spankyleo12315-Sep-09 23:08
spankyleo12315-Sep-09 23:08 
AnswerRe: C# program deployment issue Pin
Christian Graus15-Sep-09 23:12
protectorChristian Graus15-Sep-09 23:12 
AnswerRe: C# program deployment issue Pin
musefan15-Sep-09 23:16
musefan15-Sep-09 23:16 
GeneralRe: C# program deployment issue Pin
spankyleo12315-Sep-09 23:28
spankyleo12315-Sep-09 23:28 
GeneralRe: C# program deployment issue Pin
musefan15-Sep-09 23:40
musefan15-Sep-09 23:40 
Questionhow to take the text of an item in a checkedlistbox Pin
billy dev15-Sep-09 22:00
billy dev15-Sep-09 22:00 
AnswerRe: how to take the text of an item in a checkedlistbox Pin
Christian Graus15-Sep-09 22:03
protectorChristian Graus15-Sep-09 22:03 
AnswerRe: how to take the text of an item in a checkedlistbox Pin
Abhishek Sur15-Sep-09 22:21
professionalAbhishek Sur15-Sep-09 22:21 
QuestionHow to log-on a windows xp user Pin
SummerBulb15-Sep-09 21:56
SummerBulb15-Sep-09 21:56 
AnswerRe: How to log-on a windows xp user Pin
Christian Graus15-Sep-09 22:00
protectorChristian Graus15-Sep-09 22:00 
AnswerRe: How to log-on a windows xp user Pin
musefan15-Sep-09 22:00
musefan15-Sep-09 22:00 
GeneralRe: How to log-on a windows xp user Pin
SummerBulb15-Sep-09 22:06
SummerBulb15-Sep-09 22:06 
AnswerRe: How to log-on a windows xp user Pin
SummerBulb15-Sep-09 22:45
SummerBulb15-Sep-09 22:45 
QuestionCascading combobox datatable bind and selected index changed event Pin
vidhyaravichandar15-Sep-09 21:23
vidhyaravichandar15-Sep-09 21:23 
AnswerRe: Cascading combobox datatable bind and selected index changed event Pin
Christian Graus15-Sep-09 21:28
protectorChristian Graus15-Sep-09 21:28 
GeneralRe: Cascading combobox datatable bind and selected index changed event Pin
vidhyaravichandar15-Sep-09 21:30
vidhyaravichandar15-Sep-09 21:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.