I'm not quite sure what you would like to achieve with this, but your DataStruct type is erroneous.
I suppose not all of his methods return LongValue.
struct DataStruct { public short ShortVale; public int IntValue; public long LongValue; public object GetBoxedShortValue() { return ShortVale; } public object GetBoxedIntValue() { return IntValue; } public object GetBoxedLongValue() { return LongValue; } }
Otherwise, you can always use the Convert class to convert between different types.
For example:
Convert.ToInt32(SomeObject);
Clarify your post (just click the edit button and edit it) if you meant something else.
By the way, the conversion from object can be quite error prone, as it is the base type of everything. Thus, object can be anything, and this means that you cannot always safely convert object to int or any other type.
Other examples:
int value; try { value = Convert.ToInt32(someObject); } catch (FormatException) {
And it is also useful:
int myValue; if (!int.TryParse(something, out myValue)) {
Hope this helps.
Venemo
source share