According to Microsoft:
The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list.
Usually it is best to define an enum directly within a namespace so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct.
However, if I try placing several enums inside a namespace but before any classes are defined, I can't use the enum.
Here's an example of what doesn't work:
namespace CommonFunctions
{
public enum fldsJobSpecs
{
fldJOBSPECS_JobNumber,
fldJOBSPECS_Nuclear,
fldJOBSPECS_PlusMinus
};
public class CommFuncs
{
.
.
.
This seems to be the only thing that works:
namespace CommonFunctions
{
public class CommFuncs
{
public enum fldsJobSpecs
{
fldJOBSPECS_JobNumber,
fldJOBSPECS_Nuclear,
fldJOBSPECS_PlusMinus
};
.
.
.
Why?
Also, when I reference the enum, I have to fully qualify the value like:
dr[(int)CommFuncs.fldsJobSpecs.fldJOBSPECS_LastUpdated].ToString()
even though I have this declarative:
using CommonFunctions;
and this code:
public CommFuncs cf = new CommFuncs();
I can't reference the enum utilizing the 'cf'
Thanks in advance,
Jerry Scannell
The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list.
Usually it is best to define an enum directly within a namespace so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct.
However, if I try placing several enums inside a namespace but before any classes are defined, I can't use the enum.
Here's an example of what doesn't work:
namespace CommonFunctions
{
public enum fldsJobSpecs
{
fldJOBSPECS_JobNumber,
fldJOBSPECS_Nuclear,
fldJOBSPECS_PlusMinus
};
public class CommFuncs
{
.
.
.
This seems to be the only thing that works:
namespace CommonFunctions
{
public class CommFuncs
{
public enum fldsJobSpecs
{
fldJOBSPECS_JobNumber,
fldJOBSPECS_Nuclear,
fldJOBSPECS_PlusMinus
};
.
.
.
Why?
Also, when I reference the enum, I have to fully qualify the value like:
dr[(int)CommFuncs.fldsJobSpecs.fldJOBSPECS_LastUpdated].ToString()
even though I have this declarative:
using CommonFunctions;
and this code:
public CommFuncs cf = new CommFuncs();
I can't reference the enum utilizing the 'cf'
Thanks in advance,
Jerry Scannell