Robert,
That would be an error if it allowed it. Because of the "ref" keyword,
that means that the method can modify the value of the parameter passed in.
If it allowed you to pass in an instance of type foo, and the method took a
parameter of type object, what if the method assigned a type other than foo
to the parameter? Upon return, the variable passed to the parameter
couldn't be accepted or accessed, since it points to a different type (and
incorrect, on top of that).
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Robert Lario said:
Yes. That is what I feared. I was hoping that since foo is of type object
that ploymorphism would take care of the up cast.
in message news:
[email protected]...
Robert,
If you are passing a parameter by reference, then you have to make sure
that the type of the variable passed in is the same as the type of the
parameter. That is why you get that error. So, if your type is of type
foo, and you are trying to pass it into a method that needs a "ref object"
it will fail, unless you create a variable of type object first and pass
that.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Thanks for the replay -- could you be more specific? I tired what I
thought
you meant -- this creates a syntax error..
robert
Take out the object reference in the function signature.
For examples sake I have made up a very simple example.
I have an object called foo1 which is of type foo. I want to be able
to
call
a funtion called myfunc as follows:
myfunc(ref foo1)
here's the function :
public void myfunc(ref object foo)
{
do some stuff
}
I get the following errors:
The best overloaded method match for myfunc(ref object)' has some
invalid
arguments
Argument '1' cannot convert from 'ref foo' to 'ref object'