maxp:Yikes so there is no 'free' way out
Right. Think about it. C# is a 'safe' language. When you want to upcast an object to anything at all, the run-time must ascertain that the object really is an instance of whatever you're trying to upcast to, so it can access the object safely. There must be a run-time cost associated with determining this, it can't be done at compile time. If the test was done when actually accessing the object, the cost would be much, much higher, so it must be done when doing the assignment.
C# is not C++ where the corresponding cast operator is a compile-time construct to tell the compiler to just change it's notion about what a bunch of bits represent. In C++ the cast operator doesn't change anything in run-time. That's also why in C++ you have a whole bunch of different cast operators for different needs, some with run-time costs.
The conclusion is that you should not be returning an 'object' in the first place, and that's why there's a win-win with type safety in C#. Generics is one way to overcome some of the issues. Using interfaces and common base classes is another. Just stay away from 'object' as much as you can.
Finally - does this really matter? The cost of a cast is, to say the least, rather small. Especially when comparing the cost of doing anything at all with a DataSet. It's not exactly a light-weight type... The discussion may be for academic purposes, but for real performance enhancement start looking for quicker wins.
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager -
http://www.axantum.com[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.