|
|
Hello everyone -
a short (noob) question:
how do i copy an object containing a Dictionary making sure that the contents of the Dictionary are copied too ?
ex.
class A
{
public Dictonary<string,string> test = new Dictionary<test,test>;
}
...
A a = new A();
A b = new A();
A.test.Add("string1","string2");
b = a; // !! should perform a deep copy of the dictionary, but only copies a reference
b["string1"]= "anotherstring"; // !does also change a's ["string1"] entry but should not!
I do not get it to work...
Anyone can help me out of my misery ?
Thanks,
Amorphis
-- modified at 10:05 Friday 2nd March, 2007
|
|
|
|
|
You need to implement the Icloneable in your dictionary and use clone, that is what it is for, deep copies.
Hope that helps.
Ben
|
|
|
|
|
You can like the other poster create your own class and add the ICloneable interface to it.
But if you're wanting a way to perform a copy of a dictionary with out deriving a new class, you can do this as well...
For dictionaries that contain ICloneable objects:
Dictionary<KeyType, ValueType> dctSource, dctClone;<br />
<br />
dctSource = new Dictionary<KeyType, ValueType>();<br />
dctClone = new Dictionary<KeyType, ValueType>();<br />
<br />
foreach (KeyType key in dctSource.Keys)<br />
dctClone[key] = dctSource[key].Clone();
For dictionaries that contain strings like in your example:
dctSource = new Dictionary<string, string>();<br />
dctClone = new Dictionary<string, string>();<br />
<br />
foreach (string key in dctSource.Keys)<br />
dctClone[key] = dctSource[key];
(You don't have to clone the strings as they are immutable.)
|
|
|
|
|
Thanks, that was the info I needed - now it works as expected
Regards,
Amorphis
|
|
|
|
|
How can i convert DRM protected Audio files(M4p,WMA format) into Unprotected audio file(WMA,MP3 format).
Bala
|
|
|
|
|
Put it simply, you can't.
|
|
|
|
|
If you have the licence of file it´s easy.
|
|
|
|
|
Yes i have a audio files which are downloaded by payment from Apple website.
So please tell me how to proceed further.
Bala
|
|
|
|
|
I just added three items in combo box and I made the SelectedIndex = 0. I would like to lock the combo box so that the user not be able to select other than the first item.
|
|
|
|
|
Just set comboBox.Enabled = false;
|
|
|
|
|
I dont like to make the enable property to false. I just want the combox to be visible and the user can show all the items in it. But will not be able to select any items from it(combo box).
|
|
|
|
|
<br />
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
comboBox1.SelectedIndex = 0;<br />
}<br />
|
|
|
|
|
how to create a numeric textbox!
i want coding...
|
|
|
|
|
MaskedTextBox[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
You could use a validator with a regular expression that only excepts number.
Do the code youself its more fun and you'll never learn otherwise.
Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture)
http:\\www.frankkerrigan.com
|
|
|
|
|
I m getting this error "Because of security restrictions,the type System.Runtime.Remoting.ObjRef cannot be accessed."I have tried many things like
<clientproviders>
<formatter ref="binary">
<serverproviders>
<formatter ref="binary" typefilterlevel="Full">
writing this in XML or in source code file like
Hashtable props = new Hashtable();
props.Add( "port", "0" );
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
chan = new TcpChannel( props, null, serverProvider );
ChannelServices.RegisterChannel( chan );
string url = String.Format( "tcp://{0}:9000/ChatServer", textServer.Text );
chatServer = (ChatApplication.ChatServerObject)Activator.GetObject( typeof(ChatApplication.ChatServerObject),url);
but it doesn't work.Itz urgent.Plz help.
Thanx in advance.
Rizvi
|
|
|
|
|
hi all,
I have a dataview where i have included sorting.
I need to have all the rows of a dataview (sorted values) as a XMLNodeList. How can i convert the dataview sorted values into a xmlnodelist.
Can anyone help me plz
Thanks in advance.
Regards
Anuradha
|
|
|
|
|
Good Day Sir/Maam,
I wish to ask a very basic question. As I understand, the Try-Catch method catches all the error exception thrown and execute something inside the catch clause. The basic try-catch example:
<br />
try<br />
{<br />
}<br />
catch<br />
{<br />
MessageBox.Show("ERROR!");<br />
}<br />
A more advance try catch is indicating the exception thrown..
<br />
try<br />
{<br />
}<br />
catch(some exception)<br />
{<br />
MessageBox.Show("ERROR!");<br />
}<br />
catch(another exception)<br />
{<br />
MessageBox.Show("ERROR!");<br />
}<br />
My Question is this, if I indicated what exceptions to catch (like in the example above), How can I tell the try-catch to catch even the exemptions that wasn't indicated.
I Mean, when comparing it to an If-ElseIf-Else statement, what is the equivalent of "ELSE" in try catch?
I hope im not confusing you.
Thank you in advance.
|
|
|
|
|
You can specify a specific exception, a base exception (that matches all specific exceptions that inherit from it), the base for all .NET exceptions, or no specific exception class at all:
try {
} catch(NullReferenceException ex) {
} catch(SystemException ex) {
} catch(Exception ex) {
} catch {
}
---
single minded; short sighted; long gone;
|
|
|
|
|
be very careful catching totally unexpected errors. Trapping errors and 'swallowing' them can lead to some very hard to find problems further down the road.
Russ
|
|
|
|
|
Hi,
yes, just specify one or more catch blocks; their order is important, the first one
that matches gets executed, the others not.
And in general dont ignore exceptions, i.e. dont create empty catch blocks; they
would completely hide a malfunction that sooner or later will puzzle you forever.
|
|
|
|
|
Totally Right! I once created a catch block that contains //Do Nothing then I created an unexpected exception and it took me 7 hours to find.
|
|
|
|
|
How can I disable the 'information dialog' that pops up before the print
preview form shows itself?
|
|
|
|
|
by not using PrintDialog at all.
|
|
|
|