Click here to Skip to main content
15,888,052 members
Home / Discussions / C#
   

C#

 
GeneralRe: Understanding Jagged Arrays Pin
Jasmine250120-May-13 10:52
Jasmine250120-May-13 10:52 
GeneralRe: Understanding Jagged Arrays Pin
N8tiv20-May-13 10:57
N8tiv20-May-13 10:57 
GeneralRe: Understanding Jagged Arrays Pin
N8tiv20-May-13 11:06
N8tiv20-May-13 11:06 
GeneralRe: Understanding Jagged Arrays Pin
Jasmine250120-May-13 11:18
Jasmine250120-May-13 11:18 
GeneralRe: Understanding Jagged Arrays Pin
N8tiv20-May-13 12:00
N8tiv20-May-13 12:00 
GeneralRe: Understanding Jagged Arrays Pin
Jasmine250120-May-13 12:47
Jasmine250120-May-13 12:47 
GeneralRe: Understanding Jagged Arrays Pin
N8tiv20-May-13 13:04
N8tiv20-May-13 13:04 
GeneralRe: Understanding Jagged Arrays Pin
Jasmine250120-May-13 13:31
Jasmine250120-May-13 13:31 
Everything he writes is good. I lived that history and it is fascinating. C# (and Java and other "managed" languages) solves a lot of the problems that C++ had where simple coding mistakes could lead to memory leaks and security problems. In C#, a lot of those coding mistakes just won't compile... like this...

if (x = y) {
   //do something
}


In C++ that was an "assignment and test" all in one line. It assigns the value of y to x and casts the whole expression to boolean, so if y was non-zero, the branch would execute. We almost never did that on purpose, we usually just forgot to say ==(the equality operator) instead of =(the assignment operator). You can still make this mistake in Javascript.

In C# we have to write it this way...

C#
x = y;
if (x != 0) {
  //do something
}


It forces us to do the assignment and the test separately. This avoids the problem that often we would mistakenly write the first example, when what we meant was a simple test for equality. There's nothing illegal about doing assignment and testing in the same statement, but the C# compiler warns us that it's probably a mistake - you can force it to compile if you really want.

What I'm saying is C# (and Java) is mostly a reaction to C++ and all of the horrible things it would let you do! So, that's why it's helpful to see an example from old languages periodically and an explanation of why we don't do it that way any more, or why we do. In C#, arrays are managed objects, which is a step up from blocks of memory, but that managed object is just insulating you from all the mistakes that were easy to make when you were closer to the block of memory, which is still there, buried beneath objects. I would expect Petzold to cover that - how C++ was dangerous with memory, how we learned all the pitfalls, and built in safeguards right in the language.
GeneralRe: Understanding Jagged Arrays Pin
N8tiv20-May-13 13:41
N8tiv20-May-13 13:41 
GeneralRe: Understanding Jagged Arrays Pin
N8tiv23-May-13 21:17
N8tiv23-May-13 21:17 
Questioncounting in c# Pin
MKS Khalid20-May-13 0:50
MKS Khalid20-May-13 0:50 
AnswerRe: counting in c# Pin
Eddy Vluggen20-May-13 1:17
professionalEddy Vluggen20-May-13 1:17 
AnswerRe: counting in c# Pin
Pete O'Hanlon20-May-13 1:26
mvePete O'Hanlon20-May-13 1:26 
AnswerRe: counting in c# Pin
Keith Barrow20-May-13 2:12
professionalKeith Barrow20-May-13 2:12 
AnswerRe: counting in c# Pin
Richard MacCutchan20-May-13 3:10
mveRichard MacCutchan20-May-13 3:10 
GeneralRe: counting in c# Pin
MKS Khalid20-May-13 8:32
MKS Khalid20-May-13 8:32 
AnswerRe: counting in c# Pin
Abhinav S20-May-13 5:13
Abhinav S20-May-13 5:13 
Questionnested for Pin
MKS Khalid19-May-13 21:42
MKS Khalid19-May-13 21:42 
AnswerRe: nested for Pin
Richard MacCutchan19-May-13 21:55
mveRichard MacCutchan19-May-13 21:55 
AnswerRe: nested for Pin
Keith Barrow19-May-13 22:46
professionalKeith Barrow19-May-13 22:46 
AnswerRe: nested for Pin
Abhinav S20-May-13 0:36
Abhinav S20-May-13 0:36 
QuestionC# Assignment Pin
Member 1006323419-May-13 9:14
Member 1006323419-May-13 9:14 
AnswerRe: C# Assignment - Repost Pin
Richard MacCutchan19-May-13 9:36
mveRichard MacCutchan19-May-13 9:36 
GeneralRe: C# Assignment - Repost Pin
Member 1006323419-May-13 9:37
Member 1006323419-May-13 9:37 
GeneralRe: C# Assignment - Repost Pin
Richard MacCutchan19-May-13 9:46
mveRichard MacCutchan19-May-13 9:46 

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.