D
Dave Veeneman
Can I pass a method pass one of its out parameters to another method? C# is
telling me I can't.
Let's say I have two methods, FooManager and FooWorker. FooManager is part
of a class that acts as a coordinator for several other classes. FooManager
basically passes its parameters, including an output parameter 'x', on to
FooWorker, a worker method in another class. FooWorker does the actual work
and assigns to x. When FooWorker is done, it returns to FooManager, which
returns to the caller. It looks like this:
public object FooManager(object a, object b, out object x)
{
... (do some work)...
object result = FooWorker(a, b, out x);
return result;
}
Here's my problem: The C# compiler is throwing this compile-time error: "The
out parameter 'dictionary' must be assigned to before control leaves the
current method." I understand what it's saying-- it wants me to do something
with op before I send it to FooWorker. And from that it sounds like I can't
pass out parameters along from coordinator objects to worker objects.
Is there any way to pass an out parameter in the manner I've described? I'm
stuck with using an out parameter, for reasons I won't go into. Besides, I'm
out of aspirin...
Thanks for your help.
telling me I can't.
Let's say I have two methods, FooManager and FooWorker. FooManager is part
of a class that acts as a coordinator for several other classes. FooManager
basically passes its parameters, including an output parameter 'x', on to
FooWorker, a worker method in another class. FooWorker does the actual work
and assigns to x. When FooWorker is done, it returns to FooManager, which
returns to the caller. It looks like this:
public object FooManager(object a, object b, out object x)
{
... (do some work)...
object result = FooWorker(a, b, out x);
return result;
}
Here's my problem: The C# compiler is throwing this compile-time error: "The
out parameter 'dictionary' must be assigned to before control leaves the
current method." I understand what it's saying-- it wants me to do something
with op before I send it to FooWorker. And from that it sounds like I can't
pass out parameters along from coordinator objects to worker objects.
Is there any way to pass an out parameter in the manner I've described? I'm
stuck with using an out parameter, for reasons I won't go into. Besides, I'm
out of aspirin...
Thanks for your help.