What are good resources for learning generics?

Can someone help me where to start and what are the main things to learn about collections (non-generics) and generics?

+3
source share
4 answers

I also recommend the following book, which contains almost all the details that you might wish for in Generics in .NET 2.0, including common classes, methods, delegates, and restrictions, how they differ from C ++ templates and generics in BCL.

+3
source

: . , , . , . , . String.

PK .

+3

1) .

 public class MyClass<TClass>

2) .

where TClass: struct

3) .

public TMethod ConvertTo<TMethod>()

4)

public class MyClass<TClass> where TClass: struct
{
    private TClass _Instance;

    public MyClass(TClass instance)
    {
        _Instance = instance;
    }

    public TMethod ConvertTo<TMethod>()
    {
        return (TMethod)Convert.ChangeType(_Instance, typeof(TMethod));
    }
}
+2

Source: https://habr.com/ru/post/1715818/


All Articles