Click here to Skip to main content
15,907,183 members
Home / Discussions / C#
   

C#

 
Questionsliding desktop bar in C# Pin
danilsk16-Sep-09 0:35
danilsk16-Sep-09 0:35 
AnswerRe: sliding desktop bar in C# Pin
Christian Graus16-Sep-09 1:23
protectorChristian Graus16-Sep-09 1:23 
GeneralRe: sliding desktop bar in C# Pin
danilsk16-Sep-09 3:57
danilsk16-Sep-09 3:57 
GeneralRe: sliding desktop bar in C# Pin
danilsk16-Sep-09 7:45
danilsk16-Sep-09 7:45 
AnswerRe: sliding desktop bar in C# Pin
carlecomm21-Sep-09 21:55
carlecomm21-Sep-09 21:55 
Questionprintpreview Pin
sepehr_sepehr15-Sep-09 23:35
sepehr_sepehr15-Sep-09 23:35 
AnswerRe: printpreview Pin
stancrm16-Sep-09 0:16
stancrm16-Sep-09 0:16 
AnswerRe: printpreview Pin
carlecomm21-Sep-09 21:50
carlecomm21-Sep-09 21:50 
QuestionJava Web Service and C# return as empty Pin
nhss15-Sep-09 23:27
nhss15-Sep-09 23:27 
AnswerRe: Java Web Service and C# return as empty Pin
Manas Bhardwaj16-Sep-09 0:01
professionalManas Bhardwaj16-Sep-09 0:01 
AnswerRe: Java Web Service and C# return as empty Pin
Christian Graus16-Sep-09 1:28
protectorChristian Graus16-Sep-09 1:28 
GeneralRe: Java Web Service and C# return as empty Pin
EliottA16-Sep-09 1:44
EliottA16-Sep-09 1:44 
Questionbackup and restore [modified] Pin
sos_amin15-Sep-09 23:25
sos_amin15-Sep-09 23:25 
AnswerRe: backup and restore Pin
Harvey Saayman15-Sep-09 23:30
Harvey Saayman15-Sep-09 23:30 
AnswerOh Hang on Pin
Keith Barrow15-Sep-09 23:31
professionalKeith Barrow15-Sep-09 23:31 
AnswerRe: backup and restore Pin
rakesh_choudhury15-Sep-09 23:47
rakesh_choudhury15-Sep-09 23:47 
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 

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.