Click here to Skip to main content
15,895,370 members
Home / Discussions / C#
   

C#

 
AnswerRe: Using Volume Shadow Service? Pin
Dave Kreskowiak23-Oct-07 13:59
mveDave Kreskowiak23-Oct-07 13:59 
Questionneed program Pin
dharikitty23-Oct-07 10:07
dharikitty23-Oct-07 10:07 
AnswerRe: need program Pin
pmarfleet23-Oct-07 10:22
pmarfleet23-Oct-07 10:22 
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 
For my current (and first) project in C# / ASP.net 2.0 I need some set operations (like intersect, union, minus), preferrably for a SortedList. Since I didn't find any, I wrote my own.

The problem is, it seems the method affects the objects outside the method, even though I'm sure I called the method using call by value instead of call by reference.

This is the method Minus:
<code>
public SortedList Minus(SortedList a, SortedList b)
{
/*
* Bildet a \ b
* Values werden aus a übernommen.
*
*/
if (a != null && b != null)
{
for (int i = 0; i < b.Count; i++)
{
if (a.ContainsKey(b.GetKey(i)))
{
a.Remove(b.GetKey(i));
}
}
return a;
}
else
{
return new SortedList();
}

}
</code>
And here's how I call it.
<code>
SortedList sl1 = new SortedList();
SortedList sl2 = new SortedList();
SortedList sl3 = new SortedList();

sl1.Add("1", "eins");
sl1.Add("2", "zwei");
sl1.Add("3", "drei");

sl2.Add("2", "dkjfs");



Response.Write("before: sl1: <br />\n");
helper_show_sortedlist(sl1);
Response.Write("before: sl2: <br />\n");
helper_show_sortedlist(sl2);

//sl3 = Minus((SortedList)sl1.Clone(),(SortedList)sl2.Clone());
sl3 = Minus(sl1, sl2);

Response.Write("<br />\n");

Response.Write("after: sl1: <br />\n");
helper_show_sortedlist(sl1);
Response.Write("after: sl2: <br />\n");
helper_show_sortedlist(sl2);
Response.Write("after: sl3: <br />\n");
helper_show_sortedlist(sl3);

</code>

If I do Minus(sll, sl2), the output is
<code>
before: sl1:
i=0: Key: 1, Value: eins
i=1: Key: 2, Value: zwei
i=2: Key: 3, Value: drei
before: sl2:
i=0: Key: 2, Value: dkjfs

after: sl1:
i=0: Key: 1, Value: eins
i=1: Key: 3, Value: drei
after: sl2:
i=0: Key: 2, Value: dkjfs
after: sl3:
i=0: Key: 1, Value: eins
i=1: Key: 3, Value: drei
</code>
Obviously, the Method acted like if I gave only a reference to sl1 and sl2 and changed sl1!

If I call it explicitly with copies of the two SortedLists, it gives the behaviour I would normally expect from the first way already:
<code>
before: sl1:
i=0: Key: 1, Value: eins
i=1: Key: 2, Value: zwei
i=2: Key: 3, Value: drei
before: sl2:
i=0: Key: 2, Value: dkjfs

after: sl1:
i=0: Key: 1, Value: eins
i=1: Key: 2, Value: zwei
i=2: Key: 3, Value: drei
after: sl2:
i=0: Key: 2, Value: dkjfs
after: sl3:
i=0: Key: 1, Value: eins
i=1: Key: 3, Value: drei
</code>

So I'm just wondering what I'm doing wrong here. I'd like to call methods like this the "normal" call-by-value-way, without explicitly giving them copies of what I'm going to give them.
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 
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 

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.