草庐IT

BuildClause

全部标签

C# 泛型和类型检查

我有一个使用IList的方法作为参数。我需要检查那个T的类型对象是并基于它做一些事情。我正在尝试使用T值,但编译器不允许。我的解决方案如下:privatestaticstringBuildClause(IListclause){if(clause.Count>0){if(clause[0]isint||clause[0]isdecimal){//dosomething}elseif(clause[0]isString){//dosomethingelse}elseif(...)//etcforallthetypeselse{thrownewApplicationException("I

C# 泛型和类型检查

我有一个使用IList的方法作为参数。我需要检查那个T的类型对象是并基于它做一些事情。我正在尝试使用T值,但编译器不允许。我的解决方案如下:privatestaticstringBuildClause(IListclause){if(clause.Count>0){if(clause[0]isint||clause[0]isdecimal){//dosomething}elseif(clause[0]isString){//dosomethingelse}elseif(...)//etcforallthetypeselse{thrownewApplicationException("I