Fairly new to C# programming, but very familiar with C and decent with C++. I am in the processing of making an attempt to convert an old C & C++ library over to the new language, but having some difficulties in the process.

Now the problem exactly is that I am taking data in one form or another (through the use of an Object), converting it to an array of Byte (through the System.BitConverter.GetBytes method). This class dissects the data based on parameters, does necessary changes, etc. etc. and this leads me to the actual problem. I need to convert the Byte array back into the form of data it was originally, passing it as an Object. I honestly wish the ToChar, ToString, ToInt32, etc. methods all returned Objects for delegates would make this a very easy task. However, since that doesn't seem to be an option, is there perhaps something I am missing? The two methods I have considered, and this could be only because of my familiarity with the previous two languages and me being very new to C#, are as follows (the second example includes more detailed pseudo as to processing for a specific Type so then you can see the exact method I'm considering). I'm not sure how casting from Byte[] to Char[], String, Double, Single, etc. would otherwise be done as I can't find anything other then the BitConverter class. I haven't considered direct casting, though I guess that might work as well? Figured there was a reason why the BitConverter (and possibly others) were supplied.

My train of thought kinda went as follows... Object is similar to what I would be familiar with... the lovely void*. So in this assumption, unless I'm totally off, by returning an Object I could essentially cast the Object to what it technically already is... (in the second example below, and the Char pseudo example, retCharArray=(Char[])retObj).

Code:
// pseudo-code, if-style
if (dataType == Char) {}
else if (dataType == Double) {}
else if (dataType == Int32) {}
.
.
.
Code:
// pseudo-code, switch-style
switch (dataType)
{
         case Char:
                   new CharArray (Length/2+1)
                   foreach Byte[2] in data // needs a for/while/etc. loop
                          CharArray[cur] = BitConverter.ToChar(...)
                   CharArray[last] = NULL Terminator
                   return (Object)CharArray;
                   break;
         case String:
                   break;
         case Double:
                   break;
         .
         .
         .
}