none
Which collection class to use for <string, double, double> triplets RRS feed

  • Question

  • Dears,

    The aim is to store data which is collection of triplets: string (key), double, double.

    E.g.: City (key), Min Temp, Max Temp

    Operations on this would be fetching values based on key string.

    There are thousands of tuples to be stored. I thought of storing them in a database; but then, on second thought, I want to see if any of .NET collection classes could of use with proper algorithms to retrieve values.

    Please help. Also, what is the trade-off between database and a collection-class implementation in this case?

    Regards,

    Vivek

    Wednesday, November 28, 2012 5:53 AM

Answers

  • Hi Vivek, you can just create a class which holds your 2 double values and then use a dictionary( of string,yourclass) to store the city as key ( the of string) and your class as the valuemember. Another way would be to use a list or some other collection of a tuple: http://msdn.microsoft.com/en-us/library/system.tuple.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Wednesday, November 28, 2012 6:31 AM
  • Since you've mentioned thousands of tuples, it is better to approach with a database table with spatial column type. Be aware that .NET collections such as dictionaries are capable of storing hundreds of thousands of key/value pairs, but this of course has the trade off memory consumption, and search complexity stuff, so if you've don't have any restriction on using a database, then go ahead.

    Microsoft Certified Technology Specialist, Web Development with .NET 4.0.


    Wednesday, November 28, 2012 6:38 AM
  • In regards to "storage', recognize that VS collections are volatile, and the storage only lasts for the duratioon of the program. For more permanent storage, you will require a disk-based storage mechanims, such as a database, Excel FIle, or XML.

    This may seem obvious, but we get all sorts of questiosn on this forum so I wanted to make sure you were aware of this.


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer

    Wednesday, November 28, 2012 7:47 AM

All replies

  • Hi Vivek, you can just create a class which holds your 2 double values and then use a dictionary( of string,yourclass) to store the city as key ( the of string) and your class as the valuemember. Another way would be to use a list or some other collection of a tuple: http://msdn.microsoft.com/en-us/library/system.tuple.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Wednesday, November 28, 2012 6:31 AM
  • Since you've mentioned thousands of tuples, it is better to approach with a database table with spatial column type. Be aware that .NET collections such as dictionaries are capable of storing hundreds of thousands of key/value pairs, but this of course has the trade off memory consumption, and search complexity stuff, so if you've don't have any restriction on using a database, then go ahead.

    Microsoft Certified Technology Specialist, Web Development with .NET 4.0.


    Wednesday, November 28, 2012 6:38 AM
  • In regards to "storage', recognize that VS collections are volatile, and the storage only lasts for the duratioon of the program. For more permanent storage, you will require a disk-based storage mechanims, such as a database, Excel FIle, or XML.

    This may seem obvious, but we get all sorts of questiosn on this forum so I wanted to make sure you were aware of this.


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer

    Wednesday, November 28, 2012 7:47 AM
  • Pieter,

    i have seen you becoming quite active in these forums. I just want to ask you, if you want to change your forums view from Flat List View to Threaded List View. Currently you click on Reply of the last post and it looks ( for users who use Threaded List View ) like you are replying to another post.

    Like:

    If you want to change the view, you need to go to he My Settings page. On the top of that page you can change the view.


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Wednesday, November 28, 2012 8:24 AM
  • Thanks Heslacher; I will try it out.

    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer

    Thursday, November 29, 2012 9:41 AM