本文介绍了是否有约束将我的通用方法限制为数字类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 任何人都可以告诉我是否有一种方法可以将泛型类型参数 T 限制为: Int16 Int32 li> Int64 UInt16 li> UInt32 li> 我知道关键字,但是找不到接口 $ c $ c> static bool IntegerFunction< T>(T value)其中T:INumeric 解决方案 Hejlsberg描述了未实施此功能的原因在采访中 with Bruce Eckel。 我不得不承认,我不知道他怎么认为他的建议的解决方法会奏效。他的建议是将算术运算推迟到其他通用类(阅读面试!)。这有什么帮助? IMHO,不多。 Can anyone tell me if there is a way with generics to limit a generic type argument T to only:Int16Int32Int64UInt16UInt32UInt64I'm aware of the where keyword, but can't find an interface for only these types,Something like:static bool IntegerFunction<T>(T value) where T : INumeric 解决方案 Hejlsberg has described the reasons for not implementing the feature in an interview with Bruce Eckel.I have to admit, though, that I don't know how he thinks his proposed workaround will work. His proposal is to defer arithmetic operations to some other generic class (read the interview!). How does this help? IMHO, not much. 这篇关于是否有约束将我的通用方法限制为数字类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 04:48