How to do an enumeration in an interface?

  • Thread starter Thread starter Richard Lewis Haggard
  • Start date Start date
R

Richard Lewis Haggard

I have a situation where I have to combine an enumerated value with an
interface. How can this be done?

namespace Stuff
{
public interface IThing
{
// This doesn't work, of course...
public enum EnumeratedStuff
{
None, First, Second
}

bool SomeMethod();
}
}

namespace Stuff
{
public class Thing : IThing
{
// Implement the enumerated EnumeratedStuff.

bool SomeMethod()
{
return true;
}
}
}
 
Richard said:
I have a situation where I have to combine an enumerated value with an
interface. How can this be done?

namespace Stuff
{
public interface IThing
{
// This doesn't work, of course...
public enum EnumeratedStuff
{
None, First, Second
}

bool SomeMethod();
}
}

namespace Stuff
{
public class Thing : IThing
{
// Implement the enumerated EnumeratedStuff.

bool SomeMethod()
{
return true;
}
}
}

Do you mean something like this:

namespace Stuff
{
public interface IThing
{
bool SomeMethod();
EnumeratedStuff EnumStuff{ get;set; }
}

public enum EnumeratedStuff
{
None, First, Second
}
}

namespace Stuff
{
public class Thing : IThing
{
private EnumeratedStuff es = EnumeratedStuff.None;

public bool SomeMethod()
{
return true;
}

public EnumeratedStuff EnumStuff
{
get { return this.es; }
set { this.es = value; }
}
}
}
 
Richard,

You can't do that. The enumeration has to be defined outside of the
interface, and you can't declare that the interface has to declare an
enumeration type with that name.
 
Back
Top