Click here to Skip to main content
16,017,852 members
Home / Discussions / C#
   

C#

 
AnswerRe: need program Pin
il_masacratore23-Oct-07 11:09
il_masacratore23-Oct-07 11:09 
AnswerRe: need program Pin
Spacix One23-Oct-07 11:16
Spacix One23-Oct-07 11:16 
AnswerRe: need program Pin
Guffa23-Oct-07 11:45
Guffa23-Oct-07 11:45 
AnswerRe: need program Pin
Ravi Bhavnani23-Oct-07 17:51
professionalRavi Bhavnani23-Oct-07 17:51 
QuestionProblem with SortedList and call by value Pin
sf10123-Oct-07 9:02
sf10123-Oct-07 9:02 
AnswerRe: Problem with SortedList and call by value Pin
Dave Kreskowiak23-Oct-07 9:38
mveDave Kreskowiak23-Oct-07 9:38 
AnswerRe: Problem with SortedList and call by value Pin
pmarfleet23-Oct-07 9:44
pmarfleet23-Oct-07 9:44 
AnswerRe: Problem with SortedList and call by value Pin
Luc Pattyn23-Oct-07 11:56
sitebuilderLuc Pattyn23-Oct-07 11:56 
Hi,

Two comments:

1.
yes a and b are passed by value, but the "value" of a reference type is a reference,
so Minus can (and will) change the objects a and/or b point to, but it can not change
the value of a or b themselves.

if you were to add a "ref" keyword, then Minus could not only modify the SortedLists
you pass to it, but it could also change the references themselves (i.e. make the
caller suddenly hold an entirely different SortedList object).

2.
I don't like your Minus method, for two reasons:

2a.
you should preceed it with some comments explaining exactly what functionality it offers.
Yours would be: "calculates and returns the difference of two SortedLists while destroying
one of them".

2b.
you should choose a better method definition, here are two suggestions, pick one:

(A)
<br />
// subtracts b from a (i.e. removes from a any key that is present in b)<br />
public void Minus(SortedList a, SortedList b)

The comments makes clear a will be modified, and nothing gets returned.

(B)
// calculates the difference a-b b (i.e. returns a SortedList containing those elements
that appear in a but don't appear in b; it does not modify a nor b)
public SortedList Minus(SortedList a, SortedList b)
Now here the code must make sure a is not altered, so a new SortedList must be created;
you could start of this a Clone of a, or with an empty SortedList and add what is
required.

The way you had Minus() was a mix of both, it did return something and did modify
one of its inputs, not a clear situation for the caller.

Hope this helps.

Smile | :)



Luc Pattyn [Forum Guidelines] [My Articles]


this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google


Questionerror Pin
memaia23-Oct-07 8:52
memaia23-Oct-07 8:52 
AnswerRe: error Pin
pmarfleet23-Oct-07 9:33
pmarfleet23-Oct-07 9:33 
AnswerRe: error [modified] Pin
Dave Kreskowiak23-Oct-07 9:36
mveDave Kreskowiak23-Oct-07 9:36 
GeneralRe: error Pin
Anthony Mushrow23-Oct-07 10:51
professionalAnthony Mushrow23-Oct-07 10:51 
GeneralRe: error Pin
Luc Pattyn23-Oct-07 11:59
sitebuilderLuc Pattyn23-Oct-07 11:59 
GeneralRe: error Pin
Dave Kreskowiak23-Oct-07 13:54
mveDave Kreskowiak23-Oct-07 13:54 
QuestionHow add data into DataGrid dynamically Pin
A.Asif23-Oct-07 8:25
A.Asif23-Oct-07 8:25 
AnswerRe: How add data into DataGrid dynamically Pin
pmarfleet23-Oct-07 9:30
pmarfleet23-Oct-07 9:30 
GeneralRe: How add data into DataGrid dynamically Pin
A.Asif23-Oct-07 9:46
A.Asif23-Oct-07 9:46 
GeneralRe: How add data into DataGrid dynamically Pin
pmarfleet23-Oct-07 9:55
pmarfleet23-Oct-07 9:55 
AnswerRe: How add data into DataGrid dynamically Pin
kenprog23-Oct-07 14:46
kenprog23-Oct-07 14:46 
Questioncan't play song ! Pin
whale8423-Oct-07 8:23
whale8423-Oct-07 8:23 
AnswerRe: can't play song ! Pin
pmarfleet23-Oct-07 9:26
pmarfleet23-Oct-07 9:26 
JokeRe: can't play song ! Pin
Luc Pattyn23-Oct-07 12:02
sitebuilderLuc Pattyn23-Oct-07 12:02 
GeneralRe: can't play song ! Pin
pmarfleet23-Oct-07 12:35
pmarfleet23-Oct-07 12:35 
GeneralRe: can't play song ! Pin
Luc Pattyn23-Oct-07 14:20
sitebuilderLuc Pattyn23-Oct-07 14:20 
AnswerRe: can't play song ! Pin
Anthony Mushrow23-Oct-07 10:56
professionalAnthony Mushrow23-Oct-07 10:56 

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.