locked
what is the difference between Tuple and dictionary, List etc RRS feed

  • Question

  • User264732274 posted

    just like to know difference between Tuple and dictionary, List etc with example and also discuss in what kind of situation people should use tuple not other type.

    thanks

    Tuesday, November 17, 2015 4:22 AM

Answers

  • User1100692814 posted

    A list can store a sequence of objects in a certain order such that you can index into the list, or iterate over the list. List is a mutable type meaning that lists can be modified after they have been created.

    A tuple is similar to a list except it is immutable. There is also a semantic difference between a list and a tuple. To quote Nikow's answer:

    Tuples have structure, lists have order.

    A dictionary is a key-value store. It is not ordered and it requires that the keys are hashable. It is fast for lookups by key.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 17, 2015 4:50 AM
  • User1100692814 posted

    Hi

    Give this a read: http://www.dotnetperls.com/tuple-keyvaluepair 

    From MSDN: https://msdn.microsoft.com/en-us/magazine/dd942829.aspx#id0400060

    And this: http://stackoverflow.com/questions/24428050/what-is-the-difference-between-tuple-and-keyvaluepair

    The attached articles have code examples. Give them a read and you should get what you need.

    Hope this helps.

    D

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 17, 2015 6:02 AM
  • User-986267747 posted

    Hi sudip_inn,

    sudip_inn

    please come with sample code and situation where people prefer to use tuple not list or dictionary.

    This msdn article explains it very well with examples, "A tuple is a data structure that has a specific number and sequence of elements".

    Tuples are commonly used in four ways:

    1. To represent a single set of data. For example, a tuple can  represent a database record, and its components can represent  individual fields of the record.

    2. To provide easy access to, and manipulation of, a data set.

    3. To return multiple values from a method without using out parameters  (in C#) or ByRef parameters (in Visual Basic).

    4. To pass multiple values to a method through a single parameter. For  example, the Thread.Start(Object)method has a single parameter that  lets you supply one value to the method that the thread executes at  startup time. If you supply a Tuple<T1, T2, T3> object as the method  argument, you can supply the thread’s startup routine with three  items of data.

    Besides, you could also refer to the following link to know the tuples.

    http://www.codeproject.com/Articles/193537/C-Tuples

    I hope it's helpful to you.

    Best Regards,

    Klein zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 18, 2015 12:22 AM

All replies

  • User1100692814 posted

    A list can store a sequence of objects in a certain order such that you can index into the list, or iterate over the list. List is a mutable type meaning that lists can be modified after they have been created.

    A tuple is similar to a list except it is immutable. There is also a semantic difference between a list and a tuple. To quote Nikow's answer:

    Tuples have structure, lists have order.

    A dictionary is a key-value store. It is not ordered and it requires that the keys are hashable. It is fast for lookups by key.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 17, 2015 4:50 AM
  • User264732274 posted

    thanks for reply but you forgot to mention "in what kind of situation people should use tuple not other type."

    please come with sample code and situation where people prefer to use tuple not list or dictionary.

    thanks

    Tuesday, November 17, 2015 5:57 AM
  • User1100692814 posted

    Hi

    Give this a read: http://www.dotnetperls.com/tuple-keyvaluepair 

    From MSDN: https://msdn.microsoft.com/en-us/magazine/dd942829.aspx#id0400060

    And this: http://stackoverflow.com/questions/24428050/what-is-the-difference-between-tuple-and-keyvaluepair

    The attached articles have code examples. Give them a read and you should get what you need.

    Hope this helps.

    D

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 17, 2015 6:02 AM
  • User-986267747 posted

    Hi sudip_inn,

    sudip_inn

    please come with sample code and situation where people prefer to use tuple not list or dictionary.

    This msdn article explains it very well with examples, "A tuple is a data structure that has a specific number and sequence of elements".

    Tuples are commonly used in four ways:

    1. To represent a single set of data. For example, a tuple can  represent a database record, and its components can represent  individual fields of the record.

    2. To provide easy access to, and manipulation of, a data set.

    3. To return multiple values from a method without using out parameters  (in C#) or ByRef parameters (in Visual Basic).

    4. To pass multiple values to a method through a single parameter. For  example, the Thread.Start(Object)method has a single parameter that  lets you supply one value to the method that the thread executes at  startup time. If you supply a Tuple<T1, T2, T3> object as the method  argument, you can supply the thread’s startup routine with three  items of data.

    Besides, you could also refer to the following link to know the tuples.

    http://www.codeproject.com/Articles/193537/C-Tuples

    I hope it's helpful to you.

    Best Regards,

    Klein zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 18, 2015 12:22 AM