Hello everyone,
Here is my code to make a duplicate value copy of all the Values in a dictionary instance -- not just reference. So, I use CopyTo method.
My current issue is, I think my code is stupid but do not know how to solve it. My specific concern is,
1.
the code Foo[] FooArray = new Foo[3] creates 3 new instances of Foo, the code dic.Values.CopyTo(FooArray, 0) will overwrite the 3 new instances of Foo? So, seems it is stupid to create 3 new instances of Foo in Foo[] FooArray = new Foo[3], but never use them and overwrite them? Any ideas? Is it an issue?
2.
Maybe I am wrong, the code Foo[] FooArray = new Foo[3] creates only references variable of Foo class? Not class instances variable themselves?
[Code]
class Foo
{
public int abc;
public Foo (int i)
{
abc = i;
}
}
public static void Main()
{
Dictionary
dic.Add(1, new Foo(10));
dic.Add(1, new Foo(20));
dic.Add(3, new Foo(30));
Foo[] FooArray = new Foo[3];
dic.Values.CopyTo(FooArray, 0);
return;
}
[/Code]
thanks in advance,
George
George GeorgePosted May 20, 2008, 9:42 AM
Thanks Dipal,
I have some new ideas. I think new an array just create 3 new references, not 3 new object instances, and making the reference point to NULL.
And the dic.CopyTo statement will copy only the reference and assign each reference variable in the array (just created) to the same object pointed by the related peer reference in the Dictionary object instance. Any comments?
regards,
George
Dipal ChoksiPosted May 20, 2008, 12:51 AM