dictionary

This is a discussion on dictionary within the C# Programming forums, part of the General Programming Boards category; hello.I have a destructor and I want to remove one of my Dictionary variables(that has 2 variables).how can I do ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    5

    dictionary

    hello.I have a destructor and I want to remove one of my Dictionary variables(that has 2 variables).how can I do that?please help me

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    Umm....Dictionary(TKey, TValue).Remove Method (System.Collections.Generic)? If not, try being more specific with your question.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    It could be worth mentioning that when an object goes out of scope in .net, it doesn't necessarily mean the destructor will be called immediately. I don't use destructors very much in .net but having done a few tests it would appear the destructors are called just before the object is GC'ed.

    The point is, you can't guarantee when your dictionary variable will be deleted if the code to remove it is in a destructor... == unreliable.

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    2
    you should implement IDisposable, for the reason theoobe mentioned.

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    4
    perhaps a stupid suggestion... but if your dict will really only hold 2 values, why not use two variables

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I think he means the collection is composed of pairs which is obvious since it uses a key,value pair.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help in Dictionary Program
    By jerico in forum C Programming
    Replies: 18
    Last Post: 03-07-2011, 02:24 AM
  2. change key value of a Dictionary
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-28-2008, 08:15 PM
  3. foreach Dictionary
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-27-2008, 10:01 AM
  4. class Dictionary
    By madsiro in forum C# Programming
    Replies: 1
    Last Post: 04-20-2008, 02:52 PM
  5. May I buy you a dictionary?
    By EvenFlow in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 10-19-2001, 12:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21