阅读背景:

如何在没有自己的构造函数的基类型函数内调用泛型类型的构造函数?

来源:互联网 

I thought a great way to test my understanding of generic functions would be to create a function that would spit out a hex representation of a hash using one of the classes that inherits from HashAlgorithm. Since all of the HashAlgorithm classes offer ComputeHash, I thought this would be simple. When I construct such a function. though, I get an error because HashAlgorithm itself doesn't offer a constructor. I couldn't find any sort of interface or subclass of HashAlgorithm that does offer a constructor, either. If not all HashAlgorithm classes are required to support a constructor, is there some additional constraint I can put on a generic type to ensure a type offers an empty constructor or will I be forced to create an overload for each of the HashAlgorithm classes I know offer an empty constructor.I thought a great way to test my understanding




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: