C#
 Computer >> コンピューター >  >> プログラミング >> C#

C#でタプルの3番目の要素を取得するにはどうすればよいですか?


タプルの3番目の要素を取得するためのコードは、次のとおりです-

using System;
public class Demo {
   public static void Main(String[] args){
      var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);
      var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);
      Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));
      Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());
      Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());
      Console.WriteLine("Tuple1 Item 1st = "+tuple1.Item1);
      Console.WriteLine("Tuple2 Item 1st = "+tuple2.Item1);
      Console.WriteLine("Tuple1 Item 2nd = "+tuple1.Item2);
      Console.WriteLine("Tuple2 Item 2nd = "+tuple2.Item2);
      Console.WriteLine("Tuple1 Item 4th = "+tuple1.Item4);
      Console.WriteLine("Tuple2 Item 4th = "+tuple2.Item4);
      Console.WriteLine("Tuple1 Item 5th = "+tuple1.Item5);
      Console.WriteLine("Tuple2 Item 5th = "+tuple2.Item5);
      Console.WriteLine("Tuple1 Item 6th = "+tuple1.Item6);
      Console.WriteLine("Tuple2 Item 5th = "+tuple2.Item6);
      Console.WriteLine("Tuple1 Item 7th = "+tuple1.Item7);
      Console.WriteLine("Tuple2 Item 7th = "+tuple2.Item7);
   }
}

出力

これにより、次の出力が生成されます-

Is Tuple1 equal to Tuple2? = True HashCode of Tuple1 = 3231587
HashCode of Tuple2 = 3231587
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 5th = 1200
Tuple1 Item 7th = 1500
Tuple2 Item 7th = 1500

別の例を見てみましょう-

using System;
public class Demo {
   public static void Main(String[] args){
      var tuple = Tuple.Create(1200, 1500, 2200, 2700, 3100, 3500, 4500, 5500);
      Console.WriteLine("HashCode of Tuple = "+tuple.GetHashCode());
      Console.WriteLine("Tuple Item 1st = "+tuple.Item1);
      Console.WriteLine("Tuple Item 2nd = "+tuple.Item2);
      Console.WriteLine("Tuple Item 3rd = "+tuple.Item3);
      Console.WriteLine("Tuple Item 4th = "+tuple.Item4);
      Console.WriteLine("Tuple Item 5th = "+tuple.Item5);
      Console.WriteLine("Tuple Item 6th = "+tuple.Item6);
      Console.WriteLine("Tuple Item 7th = "+tuple.Item7);
   }
}

出力

これにより、次の出力が生成されます-

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

  1. Tkinterの右下隅に要素を貼り付ける方法は?

    Tkinterには、アプリケーションのGUIを構築するために使用できる多くの機能、関数、およびメソッドが組み込まれています。アプリケーションで特定のウィジェットの位置を設定して、本質的にレスポンシブになるようにする方法を知る必要があります。 Tkinterは、要素とウィジェットの位置を設定できるジオメトリマネージャーも提供します。プレイスジオメトリマネージャーは、複雑なウィジェットの位置を構成するために使用されます。 例 ウィジェットの位置をアプリケーションウィンドウの右下に配置したいとします。次に、場所を使用できます。 アンカーを備えたジオメトリマネージャー プロパティ。 # Impor

  2. Tkinter.Listboxのアイテムのインデックスを取得するにはどうすればよいですか?

    Tkinterリストボックスウィジェットを使用して、アイテムのリストを作成します。リストボックス内の各アイテムには、垂直方向に順番に割り当てられるいくつかのインデックスがあります。 リストボックスでクリックされたアイテムのインデックスを取得したいとします。次に、最初に list.curselection()を使用してアイテムの現在の選択をキャプチャするボタンを作成する必要があります メソッドを実行してから、 get()を使用してインデックスを出力します。 メソッド。 例 # Import the required libraries from tkinter import * # Crea