How to get the remaining elements of the Tuple in C#?

CsharpServer Side ProgrammingProgramming

<p>To get the remaining elements of the Tuple, the Rest property is used. The code is as follows &minus;</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/JKNmyIM9" rel="nofollow noopener noreferrer" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">using System; public class Demo { &nbsp; &nbsp;public static void Main(String[] args){ &nbsp; &nbsp; &nbsp; var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, 2000); &nbsp; &nbsp; &nbsp; var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, 2000); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Is Tuple1 equal to Tuple2? = &quot;+tuple1.Equals(tuple2)); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;HashCode of Tuple1 = &quot;+tuple1.GetHashCode()); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;HashCode of Tuple2 = &quot;+tuple2.GetHashCode()); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 1st = &quot;+tuple1.Item1); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 1st = &quot;+tuple2.Item1); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 2nd = &quot;+tuple1.Item2); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 2nd = &quot;+tuple2.Item2); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 4th = &quot;+tuple1.Item4); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 4th = &quot;+tuple2.Item4); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 5th = &quot;+tuple1.Item5); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 5th = &quot;+tuple2.Item5); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 6th = &quot;+tuple1.Item6); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 6th = &quot;+tuple2.Item6); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 7th = &quot;+tuple1.Item7); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 7th = &quot;+tuple2.Item7); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 rest value = &quot;+tuple1.Rest); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 rest value = &quot;+tuple2.Rest); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">Is Tuple1 equal to Tuple2? = True HashCode of Tuple1 = 3247155 HashCode of Tuple2 = 3247155 Tuple1 Item 1st = 75 Tuple2 Item 1st = 75 Tuple1 Item 2nd = 200 Tuple2 Item 2nd = 200 Tuple1 Item 4th = 700 Tuple2 Item 4th = 700 Tuple1 Item 5th = 100 Tuple2 Item 5th = 100 Tuple1 Item 6th = 1200 Tuple2 Item 6th = 1200 Tuple1 Item 7th = 1500 Tuple2 Item 7th = 1500 Tuple1 rest value = (2000) Tuple2 rest value = (2000)</pre><h2>Example</h2><p>Let us now see another example &minus;</p><p><a class="demo" href="http://tpcg.io/PcP4zb2o" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate" style="">using System; public class Demo { &nbsp; &nbsp;public static void Main(String[] args){ &nbsp; &nbsp; &nbsp; var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, Tuple.Create(&quot;AB&quot;, 2000, &quot;CD&quot;)); &nbsp; &nbsp; &nbsp; var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, Tuple.Create(2500, 3500, 4000, &quot;XY&quot;)); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Is Tuple1 equal to Tuple2? = &quot;+tuple1.Equals(tuple2)); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;HashCode of Tuple1 = &quot;+tuple1.GetHashCode()); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;HashCode of Tuple2 = &quot;+tuple2.GetHashCode()); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 1st = &quot;+tuple1.Item1); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 1st = &quot;+tuple2.Item1); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 2nd = &quot;+tuple1.Item2); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 2nd = &quot;+tuple2.Item2); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 4th = &quot;+tuple1.Item4); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 4th = &quot;+tuple2.Item4); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 5th = &quot;+tuple1.Item5); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 5th = &quot;+tuple2.Item5); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 6th = &quot;+tuple1.Item6); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 6th = &quot;+tuple2.Item6); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 Item 7th = &quot;+tuple1.Item7); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 7th = &quot;+tuple2.Item7); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple1 rest value = &quot;+tuple1.Rest); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 rest value = &quot;+tuple2.Rest); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate" style="">Is Tuple1 equal to Tuple2? = False HashCode of Tuple1 = -1121878415 HashCode of Tuple2 = -835095725 Tuple1 Item 1st = 75 Tuple2 Item 1st = 75 Tuple1 Item 2nd = 200 Tuple2 Item 2nd = 200 Tuple1 Item 4th = 700 Tuple2 Item 4th = 700 Tuple1 Item 5th = 100 Tuple2 Item 5th = 100 Tuple1 Item 6th = 1200 Tuple2 Item 6th = 1200 Tuple1 Item 7th = 1500 Tuple2 Item 7th = 1500 Tuple1 rest value = ((AB, 2000, CD)) Tuple2 rest value = ((2500, 3500, 4000, XY))</pre>
raja
Updated on 10-Dec-2019 12:20:39

Advertisements