c# - Cast with typeof -


i have type type sometype want cast in runtime

for example want :

var customers = getcustomers() sometype[]  

how this?

you cannot use as cast type known @ runtime: expression invalid @ compile-time since you'd have use typeof(t) cannot used as.

what can use though system.convert.changetype(object, type). here second parameter can use typeof(t) , combined control statement can convert input @ runtime correct type.

you should ask whether want though: types known @ runtime leave little use.

msdn: system.convert.changetype


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -