Enumerator question

  • Thread starter Thread starter csharpula csharp
  • Start date Start date
C

csharpula csharp

Hello,
I have methods which refer to some class enumerator .Should I make it
pulic or encapsulate it?
 
I'm not sure what you mean by this either. But, the typical pattern is
to make the enumerator private to its containing class and publish the
interface through a method call.

Brian
 
Hello,I will try to explain my problem:

Have an executable which can activate one of 2 silngeltones.
I need an enumerator in order to let the mrethods inside singletone know
if they were activated from executable or maybe from some other place.
I prefer no to path this enumarator in sigeltone methods arguments.
How can I do it?
Thanks
 
Hi,
Have an executable which can activate one of 2 silngeltones.

I think you mean "singleton" :)
I need an enumerator in order to let the mrethods inside singletone know
if they were activated from executable or maybe from some other place.

By "enumerator" do you mean "enum"?

You have to be clear about this since they are two very different things,
although using an enumerator for the described behavior doesn't make sense.
An enumerator is used to iterate over a collection. An enum (enumeration)
is a type that you can define to contain named integral constants. You can
define an enum like this:

public enum Vehicle
{
Car, // = 0
Truck, // = 1
Boat, // = 2
Plane // = 3
}

You don't have to but you can assign each constant a numeric value if
desired. If you're using FlagsAttribute on your enum then you'll probably
want to assign each constant to a distinct value that is bit aligned (to
serve as bit flags):

[Flags]
public enum Vehicles // note the pluralization (s) to indicate Flags
{
None = 0,
Car = 1,
Truck = 2,
Boat = 4,
Plane = 8,

ByLand = Car | Truck // = 3
}

You probably won't need to use flags but I included an example anyway for
the sake of completeness. To use the first (non-flags) enum you can pass
one of its values to a method like this:

void CallMyMethod()
{
MyMethod(Vehicle.Car);
}

void MyMethod(Vehicle vehicle)
{
Console.WriteLine(vehicle); // writes Car
}

For more info:

"C# Programmer's Reference, enum (C# Reference)"
http://msdn2.microsoft.com/en-us/library/sbbt4032.aspx
I prefer no to path this enumarator in sigeltone methods arguments.

I don't understand what you mean here. Could you please clarify this
requirement?
 
Yes,it's enum and I wanted to know what is the best way to desin this
scenario?
 
Hi,

But I asked for clarification at the end of my last post because it's still
not clear what your scenario actually is and what you need help with.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top