Click here to Skip to main content
14,137,832 members
   

C#

 
AnswerRe: I can't draw a graph from serialport Data using zedgraph Pin
Jeff_T_123416-May-19 16:57
memberJeff_T_123416-May-19 16:57 
QuestionWhy is this necessary? Pin
Brian_TheLion15-May-19 19:48
memberBrian_TheLion15-May-19 19:48 
AnswerRe: Why is this necessary? Pin
OriginalGriff15-May-19 20:05
protectorOriginalGriff15-May-19 20:05 
GeneralRe: Why is this necessary? Pin
Brian_TheLion16-May-19 13:50
memberBrian_TheLion16-May-19 13:50 
GeneralRe: Why is this necessary? Pin
OriginalGriff16-May-19 20:14
protectorOriginalGriff16-May-19 20:14 
GeneralRe: Why is this necessary? Pin
Brian_TheLion17-May-19 15:35
memberBrian_TheLion17-May-19 15:35 
GeneralRe: Why is this necessary? Pin
OriginalGriff17-May-19 20:09
protectorOriginalGriff17-May-19 20:09 
AnswerRe: Why is this necessary? Pin
OriginalGriff15-May-19 21:32
protectorOriginalGriff15-May-19 21:32 
Now I've had some coffee, I'll add some thoughts for you.
If you allowed
fox = new animal();
without the type specifier, what problems might it cause?
Well, consider this:
public animal fox { get; set; }
public void DoSummat(animal a)
   {
   fox = a;   
   ...
   }
Is the fox assignment inside DoSummat meant to create a new local instance which is scoped to just the method, or to affect the public property? How could you tell? How could I tell when I tried to fix a problem in 100,000 lines of code next year?

Worse, is fox supposed to be an animal, or a mammal, or a Canidae? Does it make a difference? Yes - it does. Because bird is a type of animal but a fox doesn't have a FlapWings method! So if you allow implicit typing, then the compiler has to assume the lowest common type in the hierarchy and that could mean that methods you expect to work just don't exist for that actual instance.

And consider this:
public void DoSummat(animal a)
   {
   fox = a;   
   ...
   fax = b;
   ...
   }
Isfax a new variable, or did I mistype fox? How would you tell?

C# is a strongly typed language: which means that there is no implicit declarations, no automatic type changing (except where data won't be lost such as int to double for example), and heavy duty type checking - which makes your code more robust because it finds problems at compile time, instead of hoping you tested all the possible routes through the code and didn't leave a "bad type" in there.
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_TheLion16-May-19 15:02
memberBrian_TheLion16-May-19 15:02 
GeneralRe: Why is this necessary? Pin
BillWoodruff17-May-19 15:18
mveBillWoodruff17-May-19 15:18 
GeneralRe: Why is this necessary? Pin
OriginalGriff17-May-19 19:59
protectorOriginalGriff17-May-19 19:59 
GeneralRe: Why is this necessary? Pin
jschell18-May-19 6:52
memberjschell18-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
protectorOriginalGriff16-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
protectorOriginalGriff16-May-19 3:55 
GeneralRe: Why is this necessary? Pin
Richard MacCutchan16-May-19 4:03
protectorRichard 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
memberBrian_TheLion16-May-19 19:12 
GeneralRe: Why is this necessary? Pin
Richard MacCutchan16-May-19 3:33
protectorRichard 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
protectorRichard MacCutchan16-May-19 3:48 
GeneralRe: Why is this necessary? Pin
Richard Deeming16-May-19 3:53
mveRichard Deeming16-May-19 3:53 
GeneralRe: Why is this necessary? Pin
Gerry Schmitz16-May-19 3:52
mveGerry Schmitz16-May-19 3:52 
GeneralRe: Why is this necessary? Pin
Brian_TheLion16-May-19 14:44
memberBrian_TheLion16-May-19 14:44 

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.


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190518.1 | Last Updated 22 May 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid