We have been discussing Tuple and its various possible uses. In almost all cases it sounds like root of evil, it makes design worse, and generally calls for a specialized class instead of Tuple everywhere it could be used.
It is supposedly close to DB but its hard to find a use for Tuple in db persistant logic code too.
Has anyone any real world good sample of Tuple use , preferably closer to some real world domain model problem or any use actualy.
Some real word problem which can be easily solved by using c language like traffic controller, vehicle parking. How can you use your programming skills to solve real world problems? We actually learn programming to solve real world problems, it’s not just for schools and academies.
Here is the List of C solved programs/examples with solutions (category wise) and detailed explanation. C Solved Programs by categories……. C program to find the sum of Series: 1/1! + 2/2! + 3/3! + 4/4! +….+ N/N! C Program to implement Matrix Multiplication using Recursion C Program to Display all Nodes in Linked List using Recursion
Many real world problem can be solved by programming like c,c++, Java, .net. Some real word problem which can be easily solved by using c language like traffic controller, vehicle parking. How can you use your programming skills to solve real world problems?
What are the real world examples in c? There are thousands of real time softwares written in C programming . C programming is sufficient language to build embedded system. 1. Operating Systems:
Tuple
is said to have been introduced to .NET 4 because some programming languages (let's say, for example, IronPython or F#) support tuples as a core feature of the language, and the .NET BCL team wanted to provide a uniform tuple type for such languages (for language interoperability reasons, I guess):
The BCL team decided to work with the F# team to standardize on one tuple type for the framework so that every language could benefit from them. (in Eric Lippert's answer to the SO question, What problem was the tuple designed to solve? )
Tuple
does not make much sense in the C# language IMHO, because C# doesn't support tuples and some associated language constructs very well; e.g. tuple "explosion": spreading a tuple over a function's parameters, or taking a function's return values (in the form of a Tuple
) and spreading it over several local variables:
Tuple<int,int> GetFoo() { … }
// v v
int (a, b) = GetFoo(); // C# doesn't support this tuple-related syntax.
That being said, if you're writing only C# code, you can usually find "better", more structured solutions than using Tuple
. For example, using tuples to return more than one value from a method (such as in GetFoo
above) is quick and convenient, but the return value doesn't have any inherent structure — you might do better with a struct
or class
type, if you're willing to take some additional time to define it.
There are many languages where it's legal to return multiple values (something like return (a, b)
instead of using ref
or out
(these are considered another root of all evils) .) Tuple
solves this problem.
Let's look at int Math.DivRem(int, int, out int)
. It could be refactored in Tuple<int, int> Math.DivRem(int, int)
. If you think that in this case instead of Tuple you should use special classes, well, for delegates the direction is the opposite: after creating hundred (tens in reality) of specialized delegates MS has created generic Action
and Func
and has begun using them.
(We will ignore that Tuple is a family of classes so using them is "slow". Premature optimization and all that beautiful things :-) )
I'll add that Tuple
solves the problem of writing short code blocks here on SO :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With