C#のペアクラス
Pairクラスは、C#を使用して値のペアを単一のリストに格納するKeyValuePairクラスです。
KeyValuePairを宣言する-
var myList = new List<KeyValuePair>string, int>>();
Now, add some elements:
myList.Add(new KeyValuePair<string, int>("Laptop", 1));
myList.Add(new KeyValuePair<string, int>("Desktop System", 2));
myList.Add(new KeyValuePair<string, int>("Tablet", 3));
myList.Add(new KeyValuePair<string, int>("Mobile", 4));
myList.Add(new KeyValuePair<string, int>("E-Book Reader", 5));
myList.Add(new KeyValuePair<string, int>("LED", 6)); 以下に示すように、KeyValuePairを表示します-
例
using System;
using System.Collections.Generic;
class Program {
static void Main() {
var myList = new List<KeyValuePair<string, int>>();
// adding elements
myList.Add(new KeyValuePair <string, int>("Laptop", 1));
myList.Add(new KeyValuePair <string, int>("Desktop System", 2));
myList.Add(new KeyValuePair <string, int>("Tablet", 3));
myList.Add(new KeyValuePair <string, int>("Mobile", 4));
myList.Add(new KeyValuePair <string, int>("E-Book Reader", 5));
myList.Add(new KeyValuePair <string, int>("LED", 6));
foreach (var val in myList) {
Console.WriteLine(val);
}
}
} 出力
[Laptop, 1] [Desktop System, 2] [Tablet, 3] [Mobile, 4] [E-Book Reader, 5] [LED, 6]
-
C#のコンソールクラス
C#のConsoleクラスは、コンソールアプリケーションの標準の入力、出力、およびエラーストリームを表すために使用されます。 C#のコンソールクラスプロパティの例をいくつか見てみましょう- Console.CursorLeftプロパティ C#でコンソールのCursorLeftを変更するには、Console.CursorLeftプロパティを使用します。 例 例を見てみましょう- using System; class Demo { public static void Main (string[] args) { Cons
-
C#のクラス
データ型のブループリントは、C#でクラスと呼ぶことができるものです。オブジェクトはクラスのインスタンスです。クラスを構成するメソッドと変数は、クラスのメンバーと呼ばれます。 例 以下は、C#のクラスの一般的な形式です- <access specifier> class class_name { // member variables <access specifier><data type> variable1; <access specifier><data