Kevin Spencer said:
Just write the object to the stream. While it is defined in your code as
"object," it is what it is. That is, while your variable is typed as
"object," the value of it will be a type. Example:
Object o = 25;
binarywriterobject.Write(o);
Because the value contained in the variable is an integer, the overload of
BinaryWriter.Write that takes an integer will be used.
I wrote a quick test just to see this in action (I'm curious even though
I've been developing VB.Net and C# for years now) ...
object a = null;
object b = 123;
object c = "123";
private void Show(object Value) { Console.WriteLine("object"); }
private void Show(int Value) { Console.WriteLine("int"); }
private void Show(string Value) { Console.WriteLine("string"); }
after running the above...I get the following output in the console window:
object
object
object
I don't mean to prove ya wrong Kev...just checking it out and found that you
were...the overloads that take an int and a string are never called...and
here is why...
When you create a variable of type object, and set it to a value type, the
variable does not hold the value. The variable is holding the "box"'ed
value. Since it's holding a box'ed value, it is seen as an object and not
the specified type (int or string). So, the first method (passing object
value) is called.
Correct me if I'm wrong, but that's how I see it happening here
Mythran