123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- ?
- using System;
- using System.Collections.Generic;
- public static class Generics
- {
- public class MyArray<T>
- {
- public class NestedClass<Y>
- {
- public T Item1;
- public Y Item2;
- }
-
- public enum NestedEnum
- {
- A,
- B
- }
-
- private T[] arr;
-
- public MyArray(int capacity)
- {
- this.arr = new T[capacity];
- }
-
- public void Size(int capacity)
- {
- Array.Resize<T>(ref this.arr, capacity);
- }
-
- public void Grow(int capacity)
- {
- if (capacity >= this.arr.Length)
- {
- this.Size(capacity);
- }
- }
- }
-
- public interface IInterface
- {
- void Method1<T>() where T : class;
- void Method2<T>() where T : class;
- }
-
- public abstract class Base : Generics.IInterface
- {
-
- public abstract void Method1<T>() where T : class;
-
-
- void Generics.IInterface.Method2<T>()
- {
- }
- }
-
- public class Derived : Generics.Base
- {
-
- public override void Method1<T>()
- {
- }
- }
-
- private const Generics.MyArray<string>.NestedEnum enumVal = Generics.MyArray<string>.NestedEnum.A;
- private static Type type1 = typeof(List<>);
- private static Type type2 = typeof(Generics.MyArray<>);
- private static Type type3 = typeof(List<>.Enumerator);
- private static Type type4 = typeof(Generics.MyArray<>.NestedClass<>);
- private static Type type5 = typeof(List<int>[]);
- private static Type type6 = typeof(Generics.MyArray<>.NestedEnum);
-
- public static void MethodWithConstraint<T, S>() where T : class, S where S : ICloneable, new()
- {
- }
-
- public static void MethodWithStructConstraint<T>() where T : struct
- {
- }
-
- public static Dictionary<string, string>.KeyCollection.Enumerator GetEnumerator(Dictionary<string, string> d, Generics.MyArray<string>.NestedClass<int> nc)
- {
-
- return d.Keys.GetEnumerator();
- }
- }
|