G
Guest
Hi,
I get the following warning:
"Possibly incorrect assignment to local 'oLockObject' which is the argument
to a using or lock statement. The Dispose call or unlocking will happen on
the original value of the local."
My code is:
using System;
using System.Collections.Generic;
using System.Text;
namespace RefLockExample
{
class Program
{
protected void MyMethod(ref Object oObject)
{
//something here
//oObject will be used, but no "new" object will be assigned to
oObject
}
static void Main(string[] args)
{
Program oProgram= new Program();
Object oLockObject;
oLockObject = new Object();
lock (oLockObject)
{
oProgram.MyMethod(ref oLockObject);
}
}
}
}
Why does this warning occur?
If I understand it right, it should not make much of a difference to leave
out the "ref".
What does actually get passed here?
I understood that object passing in .NET is passing the reference anyways
and not the value.
So, do I pass the reference on an object reference or do I pass a reference
on the object?
in the called method of course I will not assign anything "new" to the
object, but a problem with assigning anything new would be the same if I
would not have used "ref" also.
What can happen if I use this construct (example) instead of leaving out the
"ref"?
Regards,
I get the following warning:
"Possibly incorrect assignment to local 'oLockObject' which is the argument
to a using or lock statement. The Dispose call or unlocking will happen on
the original value of the local."
My code is:
using System;
using System.Collections.Generic;
using System.Text;
namespace RefLockExample
{
class Program
{
protected void MyMethod(ref Object oObject)
{
//something here
//oObject will be used, but no "new" object will be assigned to
oObject
}
static void Main(string[] args)
{
Program oProgram= new Program();
Object oLockObject;
oLockObject = new Object();
lock (oLockObject)
{
oProgram.MyMethod(ref oLockObject);
}
}
}
}
Why does this warning occur?
If I understand it right, it should not make much of a difference to leave
out the "ref".
What does actually get passed here?
I understood that object passing in .NET is passing the reference anyways
and not the value.
So, do I pass the reference on an object reference or do I pass a reference
on the object?
in the called method of course I will not assign anything "new" to the
object, but a problem with assigning anything new would be the same if I
would not have used "ref" also.
What can happen if I use this construct (example) instead of leaving out the
"ref"?
Regards,