473,503 Members | 479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to do an enumeration in an interface?

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 Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm
Aug 21 '07 #1
3 1285
Richard Lewis Haggard wrote:
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; }
}
}
}
--
Tom Porterfield
Aug 21 '07 #2
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Richard Lewis Haggard" <HaggardAtWorldDotStdDotComwrote in message
news:eP**************@TK2MSFTNGP04.phx.gbl...
>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 Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm


Aug 21 '07 #3
Greatly appreciated. Your response told me exactly what I needed to know.
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm

"Tom Porterfield" <tp******@mvps.orgwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
Richard Lewis Haggard wrote:
>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; }
}
}
}
--
Tom Porterfield

Aug 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12616
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
0
1310
by: Brian Riis | last post by:
This all pertains to the above mentioned article. Anyone want to read it (it's rather neat, actually), here's the address: http://www.cuj.com/documents/s=8205/cujweb0305meynard/ Anyway, I was...
1
3353
by: Max Akbar | last post by:
Hi all, I am trying to enumerate the elements of a Compound storage file and I get an error (System.NullReferenceException) when I execute the "EnumElements" of the "UCOMIStorage". I can open the...
6
3527
by: Jamie Winder via .NET 247 | last post by:
Is it possible to iterate through all of the possible values of an enumeration? (with foreach, maybe?) What I need to do is fill a ComboBox with all possible values for an enumeration. e.g ...
4
5644
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
2
5769
by: Jayme Pechan | last post by:
Is there a simple way to return a COM enumeration interface from .NET? I am porting a C++ COM Object that has an enumeration interface containing the DISPID_NEWENUM and DISPID_VALUE properties and...
3
2527
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
0
500
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
0
3981
by: Christian Gosselin | last post by:
The problem: We have an interface (EnumInterface), an enumeration container (EnumContainer) and an enumeration type (TheEnum). We can set the EnumContainer through the EnumInterface. However when...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.