Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, November 17, 2015 4:22 AM
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
All replies (4)
Tuesday, November 17, 2015 4:50 AM ✅Answered
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.
Tuesday, November 17, 2015 6:02 AM ✅Answered
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
Wednesday, November 18, 2015 12:22 AM ✅Answered
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:
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.
To provide easy access to, and manipulation of, a data set.
To return multiple values from a method without using out parameters (in C#) or ByRef parameters (in Visual Basic).
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
Tuesday, November 17, 2015 5:57 AM
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