I'm interested: What is C#'s analog of std::pair
in C++? I found System.Web.UI.Pair
class, but I'd prefer something template-based.
Thank you!
C is a procedural programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system.
noun plural c's, C's or Cs. the third letter and second consonant of the modern English alphabet. a speech sound represented by this letter, in English usually either a voiceless alveolar fricative, as in cigar, or a voiceless velar stop, as in case.
C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
Tuples are available since .NET4.0 and support generics:
Tuple<string, int> t = new Tuple<string, int>("Hello", 4);
In previous versions you can use System.Collections.Generic.KeyValuePair<K, V>
or a solution like the following:
public class Pair<T, U> { public Pair() { } public Pair(T first, U second) { this.First = first; this.Second = second; } public T First { get; set; } public U Second { get; set; } };
And use it like this:
Pair<String, int> pair = new Pair<String, int>("test", 2); Console.WriteLine(pair.First); Console.WriteLine(pair.Second);
This outputs:
test 2
Or even this chained pairs:
Pair<Pair<String, int>, bool> pair = new Pair<Pair<String, int>, bool>(); pair.First = new Pair<String, int>(); pair.First.First = "test"; pair.First.Second = 12; pair.Second = true; Console.WriteLine(pair.First.First); Console.WriteLine(pair.First.Second); Console.WriteLine(pair.Second);
That outputs:
test 12 true
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