有這個類:枚舉
public static class Command
{
public const string SET_STB_MEDIA_CTRL = "SET STB MEDIA CTRL ";
public static string ECHO = "ECHO";
public static string SET_CHANNEL = "SET CHANNEL ";
public static string GET_VOLUMN = "GET VOLUMN";
public static string GET_MAX_VOLUMN = "GET MAX VOLUMN ";
public string SET_STB_MEDIA_LIST = "SET STB MEDIA LIST ";
}
則:
public static class MultimediaConstants
{
public const string VIDEO = "video";
public const string AUDIO = "audio";
public const string PHOTO = "photo";
public const string ALL = "all";
public const string BACKGROUND_MUSIC = "background_music";
public const string TV = "tv";
public const string ACTION_PLAY = "play";
}
的一點是,我想有這樣的事情:
public static string SET_STB_MEDIA_CTRL (MultimediaConstants type, MultimediaConstants action)
{
return Command.SET_STB_MEDIA_CTRL + "type:" + type + "action:" + action;
}
所以此方法的結果應爲:
SET STB MEDIA CTRL type:tv action:play
方法的調用將是:
SET_STB_MEDIA_CTRL (MultimediaConstants.TV, MultimediaConstants.ACTION_PLAY);
因爲無法創建靜態類的實例,所以無法請求將靜態類的實例作爲方法參數 – Sehnsucht
這些arent枚舉。這些是類。你可以使用'enum'關鍵字而不是class來創建枚舉。那麼你可以使用你想要的值。 –
@Sehnsucht這就是爲什麼他想要'Enum of strings',就像java可以讓你做 –