Yes, as all the others have said, ref is the way to go.
However, I'm wondering why you've not done something similar to this:
static MyStateEnum ChangeToState1(MyStateEnum enState){
if ( enState == MyStateEnum.START_STATE){
enState = MyStateEnum.STATE1;
}
return enState;
}
just a thought.
On 7/12/06, Eddie Lascu <[EMAIL PROTECTED]> wrote:
Consider this:
using System;
using System.Collections.Generic;
using System.Text;
namespace TestOutParameterBehavior
{
public enum MyStateEnum
{
START_STATE = 0,
STATE1 = 1,
STATE2 = 2,
END_STATE
}
class Program
{
static void Main(string[] args)
{
MyStateEnum enState = MyStateEnum.START_STATE;
ChangeToState1(out enState);
if (enState == MyStateEnum.START_STATE)
Console.WriteLine("The state didn't change!!!");
else
Console.WriteLine("The state did change!!!");
Console.WriteLine("Press <Enter> to Exit...");
Console.ReadLine();
}
static void ChangeToState1(out MyStateEnum enState)
{
if( enState == MyStateEnum.START_STATE )
enState = MyStateEnum.STATE1;
}
}
}
Why is it that I cannot test the value of my enumeration variable before I
assign to it? This small test app doesn't compile and the errors I am
getting are:
1. Use of unassigned out parameter 'enState';
2. The out parameter 'enState' must be assigned to before control leaves
the
current method;
Obviously, I need to use 'out' parameters, because enumerations are value
types and I need to preserve the changes done in the ChangeToState1
method.
Am I missing something? Clearly this wasn't the case in VS2003 / .NET 1.1.
I
would understand the environment generating a warning in my case, but an
error? It's like I need to assign the out parameter no matter what. Well,
in
some cases (decided by the 'if' test) I don't want to do the assignment.
Regards,
Eddie
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com