Содержание
- 2. 19.1. Стек для чисел class MyFloatStack // Stack for floats { int StackPointer = 0; float
- 3. 19-2. Generic types are templates for types
- 4. 19-3. Generics and user-defined types
- 5. 19-4. Continuing with the Stack Example class MyStack { int StackPointer = 0; T [] StackArray;
- 6. 19-5. Creating instances from a generic type
- 7. 19-6. Declaring a Generic Class Type parameters ↓ class SomeClass { Normally, types would be used
- 8. 19-7. Creating a Constructed Type
- 9. 19-8. Type parameters versus type arguments
- 10. 19-9. Creating Variables and Instances MyNonGenClass myNGC = new MyNonGenClass (); Constructed class Constructed class ↓
- 11. 19-10.
- 12. 19-11. Two constructed classes created from a generic class
- 13. 19-12. Constraints on Type Parameters class Simple { static public bool LessThan(T i1, T i2) {
- 14. 19-13. Where Clauses Type parameter Constraint list ↓ ↓ where TypeParam : constraint, constraint, ... ↑
- 15. 19-14. Constraint Types and Order
- 16. 19-15. If a type parameter has multiple constraints, they must be in this order.
- 17. 19-16. Правила задания ограничений class SortedList where S: IComparable { ... } class LinkedList where M
- 18. 19-17. Generic Structs struct PieceOfData // Generic struct { public PieceOfData(T value) { _Data = value;
- 19. 19-18. Generic Structs class Program { static void Main() Constructed type { ↓ var intData =
- 20. 19-19. Generic Interfaces Type parameter ↓ interface IMyIfc // Generic interface { T ReturnIt(T inValue); }
- 21. 19-20. Generic Interfaces class Program{ static void Main(){ var trivInt = new Simple (); var trivString
- 22. 19-21. Using Generic Interfaces interface IMyIfc // Generic interface { T ReturnIt(T inValue); } Two different
- 23. 19-22. Using Generic Interfaces class Program { static void Main() { Simple trivInt = new Simple();
- 24. 19-23. Duplicate interface interface IMyIfc { T ReturnIt(T inValue); } class Simple : IMyIfc , IMyIfc
- 25. 19-24. Generic Delegates Type parameters ↓ delegate R MyDelegate ( T value ); ↑ ↑ Return
- 26. 19-25. Generic delegate and matched delegate methods delegate void MyDelegate (T value); // Generic delegate class
- 27. 19-26. Generic Delegate class Program { static void Main( ) { var myDel = // Create
- 28. 19-27. Generic Delegate public delegate TR Func (T1 p1, T2 p2); class Simple { static public
- 29. 19-28. Generic Methods
- 30. 19-29. Declaring a Generic Method Type parameter list Constraint clauses ↓ ↓ public void PrintData (
- 31. 19-30. Invoking a Generic Method Объявление обобщенного метода: void MyMethod () { T1 someVar; T2 otherVar;
- 32. 19-31. A generic method with two instantiations
- 33. 19-32. Inferring Types public void MyMethod (T myVal) { ... } ↑ ↑ Both are of
- 34. 19-33. Example of a Generic Method class Simple { // Non-generic class static public void ReverseAndPrint
- 35. 19-34. Example of a Generic Method class Program { static void Main() { var intArray =
- 36. 19-35. Extension Methods with Generic Classes static class ExtendHolder { public static void Print (this Holder
- 37. 19-36. Example class Program { static void Main(string[] args) { var intHolder = new Holder (3,
- 39. Скачать презентацию