Click here to Skip to main content
16,010,876 members
Home / Discussions / C#
   

C#

 
GeneralRe: I can't draw a graph from serialport Data using zedgraph Pin
Luc Pattyn16-May-19 16:45
sitebuilderLuc Pattyn16-May-19 16:45 
GeneralRe: I can't draw a graph from serialport Data using zedgraph Pin
Jeff_T_123416-May-19 16:47
Jeff_T_123416-May-19 16:47 
GeneralRe: I can't draw a graph from serialport Data using zedgraph Pin
Luc Pattyn16-May-19 16:49
sitebuilderLuc Pattyn16-May-19 16:49 
AnswerRe: I can't draw a graph from serialport Data using zedgraph Pin
Jeff_T_123416-May-19 16:57
Jeff_T_123416-May-19 16:57 
QuestionWhy is this necessary? Pin
Brian_TheLion15-May-19 19:48
Brian_TheLion15-May-19 19:48 
AnswerRe: Why is this necessary? Pin
OriginalGriff15-May-19 20:05
mveOriginalGriff15-May-19 20:05 
GeneralRe: Why is this necessary? Pin
Brian_TheLion16-May-19 13:50
Brian_TheLion16-May-19 13:50 
GeneralRe: Why is this necessary? Pin
OriginalGriff16-May-19 20:14
mveOriginalGriff16-May-19 20:14 
C#
public class Animal 
   {
   public void Breathe() {}
   }
public class Bird : Animal 
   {
   public void FlapWings() {}
   }
public class Eagle : Bird 
   {
   public void DiveVeryQuicklyOntoOtherBird(Bird target) {}
   }
...
Bird eagle = new Eagle();
Animal animal = eagle;
That's completely legal because Eagle is derived from Bird, which derives from Animal: an Eagle is a Bird, which is an Animal.
But ... it's legal to say these:
C#
eagle.FlapWings();
eagle.Breathe();
Because eagle is a variable containing a Bird instance (or an instance of a class derived from Bird), so it has all the properties and methods of a Bird as well as those of an Animal

But ... you can't do this:
C#
eagle.DiveVeryQuicklyOntoOtherBird(myPigeon);
Because not all the types that can be held in a Bird variable are Eagles; they could be any Bird - so they don't all support the DiveVeryQuicklyOntoOtherBird method - despite the variable currently containing an instance of an Eagle the system doesn't "know" that it always will; at a later point you could replace it with
C#
eagle = new Sparrow();
which can't dive really quickly like an apex predator!
To use the method you'd need to cast the instance:
C#
((Eagle)eagle).DiveVeryQuicklyOntoOtherBird(new Sparrow());
Or use an Eagle variable.

If you try to cast a Sparrow to an Eagle, you will get an error at run time, because that's the only time when it can check if the conversion is possible.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: Why is this necessary? Pin
Brian_TheLion17-May-19 15:35
Brian_TheLion17-May-19 15:35 
GeneralRe: Why is this necessary? Pin
OriginalGriff17-May-19 20:09
mveOriginalGriff17-May-19 20:09 
AnswerRe: Why is this necessary? Pin
OriginalGriff15-May-19 21:32
mveOriginalGriff15-May-19 21:32 
GeneralRe: Why is this necessary? Pin
Brian_TheLion16-May-19 15:02
Brian_TheLion16-May-19 15:02 
GeneralRe: Why is this necessary? Pin
BillWoodruff17-May-19 15:18
professionalBillWoodruff17-May-19 15:18 
GeneralRe: Why is this necessary? Pin
OriginalGriff17-May-19 19:59
mveOriginalGriff17-May-19 19:59 
GeneralRe: Why is this necessary? Pin
jschell18-May-19 6:52
jschell18-May-19 6:52 
AnswerRe: Why is this necessary? Pin
Richard Deeming16-May-19 1:47
mveRichard Deeming16-May-19 1:47 
GeneralRe: Why is this necessary? Pin
OriginalGriff16-May-19 2:44
mveOriginalGriff16-May-19 2:44 
GeneralRe: Why is this necessary? Pin
Gerry Schmitz16-May-19 3:49
mveGerry Schmitz16-May-19 3:49 
GeneralRe: Why is this necessary? Pin
OriginalGriff16-May-19 3:55
mveOriginalGriff16-May-19 3:55 
GeneralRe: Why is this necessary? Pin
Richard MacCutchan16-May-19 4:03
mveRichard MacCutchan16-May-19 4:03 
GeneralRe: Why is this necessary? Pin
Gerry Schmitz16-May-19 5:02
mveGerry Schmitz16-May-19 5:02 
GeneralRe: Why is this necessary? Pin
Brian_TheLion16-May-19 19:12
Brian_TheLion16-May-19 19:12 
GeneralRe: Why is this necessary? Pin
Richard MacCutchan16-May-19 3:33
mveRichard MacCutchan16-May-19 3:33 
GeneralRe: Why is this necessary? Pin
Richard Deeming16-May-19 3:41
mveRichard Deeming16-May-19 3:41 
GeneralRe: Why is this necessary? Pin
Richard MacCutchan16-May-19 3:48
mveRichard MacCutchan16-May-19 3:48 

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.