C#でスタックの一番上にあるオブジェクトを取得します
スタックの一番上にあるオブジェクトを取得するためのコードは次のとおりです-
例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
Stack<string> stack = new Stack<string>();
stack.Push("A");
stack.Push("B");
stack.Push("C");
stack.Push("D");
stack.Push("E");
stack.Push("F");
stack.Push("G");
stack.Push("H");
stack.Push("I");
stack.Push("J");
Console.WriteLine("Count of elements = "+stack.Count);
Console.WriteLine("Element at the top of stack = " + stack.Peek());
}
} 出力
これにより、次の出力が生成されます-
Count of elements = 10 Element at the top of stack = J Count of elements = 10
例
別の例を見てみましょう-
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
Stack<int> stack = new Stack<int>();
stack.Push(10);
stack.Push(20);
stack.Push(30);
stack.Push(40);
stack.Push(50);
stack.Push(60);
stack.Push(70);
stack.Push(80);
stack.Push(90);
stack.Push(100);
Console.WriteLine("Count of elements = "+stack.Count);
Console.WriteLine("Element at the top of stack = " + stack.Peek());
Console.WriteLine("Element at the top of stack = " + stack.Peek());
}
} 出力
これにより、次の出力が生成されます-
Count of elements = 10 Element at the top of stack = 100 Element at the top of stack = 100
-
アクティビティスタックで最上位のアクティビティ名を取得するにはどうすればよいですか?
この例は、アクティビティスタックで最上位のアクティビティ名を取得する方法について示しています。 ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。 ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。 <?xml version = "1.0" encoding = "utf-8"?> <LinearLayout xmlns:android = &q
-
Tkinterキャンバスでオブジェクトの座標を取得するにはどうすればよいですか?
Tkinter Canvas Widgetは、アプリケーションにGUI機能を提供します。シェイプの描画、オブジェクトのアニメーション化、およびキャンバス内の既存のアイテムの構成に使用できます。図形を作成するときは常に、Canvasアイテムコンストラクターで図形のサイズと座標を指定する必要があります。キャンバス上のアイテムの座標を返すために、 coords(item)を使用できます。 方法。キャンバスウィジェット内の形状の座標を含むリストを返します。 例 from tkinter import * #Create an instance of tkinter frame win = Tk() #