A
Andrew Bainbridge
Hi,
I'm converting some code over from vb.net to c# and have the following
issue.
In VB you can have enum's within an interface. i.e.
Public Interface Class1
Enum ColorType
Black
Red
Yellow
White
End Enum
End Interface
You don't seem to be able to do this with c#.
i.e.
namespace ClassLibrary1
{
public interface Class1
{
public enum ColorType { Black, Red, Yellow, White };
}
}
This fails with:
Error 1 'ColorType': interfaces cannot declare types
D:\Dev\test\ClassLibrary1\Class1.cs 9 17 ClassLibrary1
It is valid in VB.Net to do this. If this can't be done where is the best
place to store the enum? Could you just bump it into the namespace? i.e.
namespace ClassLibrary1
{
public enum ColorType { Black, Red, Yellow, White };
public interface Class1
{
}
}
Just trying to understand what is best practice with enums and interfaces
under c#.
Would be good if someone who has an understanding of how the compiler
converts the VB.Net code to IL so I could implement it in a similar manner
in C#.
T.I.A.
I'm converting some code over from vb.net to c# and have the following
issue.
In VB you can have enum's within an interface. i.e.
Public Interface Class1
Enum ColorType
Black
Red
Yellow
White
End Enum
End Interface
You don't seem to be able to do this with c#.
i.e.
namespace ClassLibrary1
{
public interface Class1
{
public enum ColorType { Black, Red, Yellow, White };
}
}
This fails with:
Error 1 'ColorType': interfaces cannot declare types
D:\Dev\test\ClassLibrary1\Class1.cs 9 17 ClassLibrary1
It is valid in VB.Net to do this. If this can't be done where is the best
place to store the enum? Could you just bump it into the namespace? i.e.
namespace ClassLibrary1
{
public enum ColorType { Black, Red, Yellow, White };
public interface Class1
{
}
}
Just trying to understand what is best practice with enums and interfaces
under c#.
Would be good if someone who has an understanding of how the compiler
converts the VB.Net code to IL so I could implement it in a similar manner
in C#.
T.I.A.