HashSet
1 ~ 10 の整数を追跡する を含むクラスを作成しました。メソッドを使用して、ブール値を使用しContain
て値が に挿入されているかどうかを確認しました。HashSet
これが私のコードです:
class BasicIntSet
{
HashSet<int> intTest = new HashSet<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
bool has4 = intTest.Contains(4); // Returns true
bool has11 = intTest.Contains(11); // Returns false
bool result = intTest.IsSupersetOf(new[] { 4, 6, 7 });
}
私の問題は、次のエラーが表示されることです"Error 1 A field initializer cannot reference the non-static field, method, or property"
私が間違っていることを誰かが知っていますか?