How to get Fifth Element of the Tuple in C#?

CsharpServer Side ProgrammingProgramming

<p>To get the fifth element of the Tuple, the code is as follows &minus;</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/FEc3JQOl" rel="nofollow" target="_blank">&nbsp;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); &nbsp; &nbsp; &nbsp; var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500); &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 5th = &quot;+tuple1.Item5); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple2 Item 5th = &quot;+tuple2.Item5); &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 = 3231587 HashCode of Tuple2 = 3231587 Tuple1 Item 5th = 100 Tuple2 Item 5th = 100</pre><h2>Example</h2><p>Let us see another example &minus;</p><p><a class="demo" href="http://tpcg.io/GGjSt2xk" 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 tuple = Tuple.Create(1200, 1500, 2200, 2700, 3100, 3500, 4500, 5500); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;HashCode of Tuple = &quot;+tuple.GetHashCode()); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple Item 1st = &quot;+tuple.Item1); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple Item 2nd = &quot;+tuple.Item2); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple Item 3rd = &quot;+tuple.Item3); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple Item 4th = &quot;+tuple.Item4); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple Item 5th = &quot;+tuple.Item5); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple Item 6th = &quot;+tuple.Item6); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Tuple Item 7th = &quot;+tuple.Item7); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">HashCode of Tuple = 49989024 Tuple Item 1st = 1200 Tuple Item 2nd = 1500 Tuple Item 3rd = 2200 Tuple Item 4th = 2700 Tuple Item 5th = 3100 Tuple Item 6th = 3500 Tuple Item 7th = 4500</pre>
raja
Updated on 06-Dec-2019 07:03:47

Advertisements