このインスタンスのハッシュコードをC#で取得します
このインスタンスのハッシュコードを取得するためのコードは次のとおりです-
例
using System;
public class Demo {
public static void Main() {
string[] arr = {"tom", "amit", "kevin", "katie"};
Type t1 = arr.GetType();
Type t2 = t1.GetElementType();
Console.WriteLine("Type = "+t2.ToString());
Console.WriteLine("Hash Code = "+t1.GetHashCode());
}
} 出力
これにより、次の出力が生成されます-
Type = System.String Hash Code = 9144789
例
別の例を見てみましょう-
using System;
public class Demo {
enum Vehicle {Car, Bus, Bike, Airplane}
public static void Main() {
try {
Vehicle v = Vehicle.Bike;
Type type = v.GetType();
Console.WriteLine("Hash code = "+type.GetHashCode());
string[] str = type.GetEnumNames();
Console.WriteLine("GetEnumName() to return the constant name = " + str);
Type type2 = type.GetEnumUnderlyingType();
Console.Write("Enum Underlying type = "+type2);
Array arrObj = type.GetEnumValues();
Console.Write("Values = "+arrObj);
Console.WriteLine("\nListing constants ..");
for (int i = 0; i < str.Length; i++)
Console.Write("{0} ", str[i]);
}
catch (ArgumentException e) {
Console.WriteLine("Not an enum!");
Console.Write("{0}", e.GetType(), e.Message);
}
}
} 出力
これにより、次の出力が生成されます-
Hash code = 44757566 GetEnumName() to return the constant name = System.String[] Enum Underlying type = System.Int32Values = Demo+Vehicle[] Listing constants .. Car Bus Bike Airplane
-
C#で値型CharのTypeCodeを取得します
値型CharのTypeCodeを取得するには、コードは次のとおりです- 例 using System; public class Demo { public static void Main() { char val = '5'; bool res; Console.WriteLine("Hashcode for val = "+val.GetHashCode());
-
Pythonでタイプをチェックするための標準的な方法は何ですか?
オブジェクト、xが正確に指定されたタイプ(サブタイプではない)のインスタンスであるかどうかを確認する場合は、typeを使用してそのタイプを取得し、isステートメントを使用して確認できます。 例 x = "Hello" if type(x) is str: print("x is an instance of str") 出力 これにより出力が得られます x is an instance of str xがMyClassのインスタンスであるか、MyClassのサブクラスであるかを確認する場合は、isinstanceメソッド呼び出