Is it possible to create an enum whose instance can't be created but can be used for readonly purpos
Posted
by Shantanu Gupta
on Stack Overflow
See other posts from Stack Overflow
or by Shantanu Gupta
Published on 2010-05-12T09:02:25Z
Indexed on
2010/05/12
9:14 UTC
Read the original article
Hit count: 168
I created an enum where I stored some table names. I want it to be used to get the name of the table like ds.Tables[BGuestInfo.TableName.L_GUEST_TYPE.ToString()]
.
public class a
{
public enum TableName : byte
{
L_GUEST_TYPE = 0
,L_AGE_GROUP = 1
,M_COMPANY = 2
,L_COUNTRY = 3
,L_EYE_COLOR = 4
,L_GENDER = 5
,L_HAIR_COLOR = 6
,L_STATE_PROVINCE = 7
,L_STATUS = 8
,L_TITLE = 9
,M_TOWER = 10
,L_CITY = 11
,L_REGISTER_TYPE = 12
}
}
class b
{
a.TableName x; //trying to restrict this
ds.Tables[a.TableName.L_GUEST_TYPE] //accessible and can be used like this
}
This is my enum. Now I have not created any instance of this enum so that no one can use it for other than read only purpose.
For this enum to be accessible in outer classes as well I have to make it public which means some outer class can create its object as well.
So what can i do so as to restrict its instance creation.
© Stack Overflow or respective owner