Do C# Generics Have a Performance Benefit?

前端 未结 12 1128
感动是毒
感动是毒 2020-12-13 04:26

I have a number of data classes representing various entities.

Which is better: writing a generic class (say, to print or output XML) using generics and interfaces,

12条回答
  •  猫巷女王i
    2020-12-13 04:43

    Generics are one of the way to parameterize code and avoid repetition. Looking at your program description and your thought of writing a separate class to deal with each and every data object, I would lean to generics. Having a single class taking care of many data objects, instead of many classes that do the same thing, increases your performance. And of course your performance, measured in the ability to change your code, is usually more important than the computer performance. :-)

提交回复
热议问题