1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | class PassiveAbility { } class TestClass1 : PassiveAbility { public int a = 2; } class TestClass2 : PassiveAbility { public int c = 2; } class TestClass3 : PassiveAbility { public int d = 2; } class Output { static void Main() { List<PassiveAbility> PassiveList = new List<PassiveAbility>(); PassiveList.Add( new TestClass1()); PassiveList.Add( new TestClass2()); PassiveList.Add( new TestClass3()); } } |
Поиск в листе объект класса TestClass1() и изменить его переменную(в данном случаи a)
1 | PassiveList.OfType<TestClass1>().First().a = 5; |