How do you return an Enum from a setter/getter function?
Currently I have this:
public enum LowerCase
{
a,
b,
}
public enum UpperCase
{
A,
B,
}
public enum Case
{
Upper,
Lower,
}
private Enum _Case;
private Enum _ChosenCase;
public Enum ChooseCase
{
get
{
if ('Condition')
{
return LowerCase; //[need to return LowerCase]
}
else
{
return UpperCase; //[need to return UpperCase]
}
}
set
{
_ChosenCase = value;
}
}
When I try to run this I get an error:
LowerCase is a 'type' but is used like a 'variable'
Any ideas what I need to do to return an enum????
I am also not so sure about setting the value at the moment either.
If anyone can give some general advise, I would appreciate it; most people should be able to see what I am trying to do.
Thanks very much.
[Latest Edit]
Firstly thanks to all who replied.
In an attempt to simplify this question, it appears I have used the wrong analogy of upper/lower case and some of you have got the wrong idea - clearly not your fault :)
This is the code I have so far and allows you to choose between ChoiceOne and ChoiceTwo
public partial class CustomControl1 : Control
{
public enum ChoiceOne
{
SubChoiceA,
SubChoiceB,
}
public enum ChoiceTwo
{
SubChoiceC,
SubChoiceD,
}
public enum Choice
{
ChoiceOne,
ChoiceTwo,
}
private Type _subChoice;
private Choice _choice;
public Type SetSubChoice
{
get
{
if (_choice.Equals(Choice.ChoiceOne))
{
return typeof(ChoiceOne);
}
else
{
return typeof(ChoiceTwo);
}
}
set
{
_subChoice = value;
}
}
public Choice SetChoice
{
get
{
return _choice;
}
set
{
_choice = value;
}
}
}
What happsens in VisualStudio is that property grid allows you to set the SetChoice property between ChoiceOne and ChoiceTwo which is correct.
The problem is that the SetSubChoice property is greyed out but it does set to either 'WindowsFormsApplication4.CustomControl1+ChoiceOne' or 'WindowsFormsApplication4.CustomControl1+ChoiceTwo' dependent upon what SetChoice is set to. What I want is to be able to use SetSubChoice to pick SubChoiceA or SubChoiceB or SubChoiceC or SubChoiceD depending on what SetChoice is set to.
So for example, if SetChoice is set to ChoiceOne then SetSubChoice will allow me to choose between ChoiceA or ChoiceB. Likewise if SetChoice is set to ChoiceTwo then SetSubChoice will allow me to choose between ChoiceC or ChoiceD.
Hopefully this has clarified things a little more?
We are almost there now :) keep the ideas coming.
Thanks