【发布时间】:2012-01-22 01:50:11
【问题描述】:
我正在编写一个进行强制转换的方法,我需要接收一个类型作为参数,例如:
object foo(?? type, object input) {
if(type is x ) {
Output output = new Output();
x xValue = (x) input;
foreach(var val xValue) {
//do..
}
return output;
}
if(type is y) {
Output2 output = new Output2();
y yValue = (y) input;
foreach(var val yValue) {
//do..
}
return output;
} else {
//invalid type
}
}
【问题讨论】:
-
键入
System.Type还是键入特定(或继承)类型的对象? -
一个类型为
CookieCollection,CookieContainer..
标签: c# .net type-conversion