Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program {
- static void Main(string[] args) {
- Tuple<string, int> t = new Tuple<string, int>("Hello", 4);
- PrintStringAndInt(t.Item1, t.Item2);
- }
- static void PrintStringAndInt(string s, int i) {
- Console.WriteLine("{0} {1}", s, i);
- }
- }
- var t = new Tuple<string, int>("Hello", 4);
- var t = Tuple.Create("Hello", 4);
- #region tuples
- public class Tuple<T>
- {
- public Tuple(T first)
- {
- First = first;
- }
- public T First { get; set; }
- }
- public class Tuple<T, T2> : Tuple<T>
- {
- public Tuple(T first, T2 second)
- : base(first)
- {
- Second = second;
- }
- public T2 Second { get; set; }
- }
- public class Tuple<T, T2, T3> : Tuple<T, T2>
- {
- public Tuple(T first, T2 second, T3 third)
- : base(first, second)
- {
- Third = third;
- }
- public T3 Third { get; set; }
- }
- public class Tuple<T, T2, T3, T4> : Tuple<T, T2, T3>
- {
- public Tuple(T first, T2 second, T3 third, T4 fourth)
- : base(first, second, third)
- {
- Fourth = fourth;
- }
- public T4 Fourth { get; set; }
- }
- #endregion
- public static class Tuple
- {
- //Allows Tuple.New(1, "2") instead of new Tuple<int, string>(1, "2")
- public static Tuple<T1, T2> New<T1, T2>(T1 t1, T2 t2)
- {
- return new Tuple<T1, T2>(t1, t2);
- }
- //etc...
- }
- let (a, b) = someTupleFunc
- Tuple<int,int> x = someTupleFunc();
- int a = x.get_Item1();
- int b = x.get_Item2();
- var p1 = new {a = "A", b = 3};
- Tuple<Int32, String> t1 = new Tuple<Int32, String>(10, "a");
- Tuple<Int32, String, Boolean> t2 = new Tuple<Int32, String, Boolean>(10, "a", true);
- if (t1.Equals(t2))
- Console.Out.WriteLine(t1 + " == " + t2);
- else
- Console.Out.WriteLine(t1 + " != " + t2);
- 10, a != 10, a, True
Add Comment
Please, Sign In to add comment