Understanding C# generics much better

前端 未结 4 1092
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 07:32

I looked at some sample code using C# generics. Why and when should I use them?

All the examples were complex. I need a simple, clear example that gets me started wi

4条回答
  •  死守一世寂寞
    2020-12-08 07:52

    In a nutshell, generics allow you to write classes that work with objects of any type, but without having to cast the data to Object. There are performance benefits for this, but it also makes your code more readable, maintainable, and less error-prone.

    You should always use generics as opposed to the .NET 1.1 style classes when possible.

提交回复
热议问题