我正在尝试创建一组可以作为方法变量传递的变量,如此
static class ListViewStates
{
public const int ACCOUNTVIEW = 1;
public const int LARGEIMAGEVIEW = 2;
public const int INFOVIEW = 3;
}
class ListViewHandler
{
public void SetListViewState(ListViewStates state)
{
switch(state)
{
case 1:
break;
case 2:
break;
case 3:
break;
}
}
}
class main
{
ListViewHandler listhndlr = new ListViewHandler();
listhndlr.SetListViewState(ListViewStates.ACCOUNTVIEW);
}
我如何处理ListViewStates才能使其正常工作?
我浏览了谷歌,但我似乎找不到合适的搜索词来找到答案。
答案 0 :(得分:4)
您必须使用enum
代替单独的课程。 enum
的定义如下:
enum ListViewStates
{
ACCOUNTVIEW = 1,
LARGEIMAGEVIEW = 2,
INFOVIEW = 3,
}
要访问此项,您必须重写方法签名,如下所示:
public void SetListViewState(ListViewStates state)
{
switch (state)
{
case ListViewStates.ACCOUNTVIEW:
break;
case ListViewStates.LARGEIMAGEVIEW:
break;
case ListViewStates.INFOVIEW:
break;
}
}
答案 1 :(得分:3)
您可能想要enum
,而不是static class
:
public enum ListViewStates
{
ACCOUNTVIEW = 1,
LARGEIMAGEVIEW = 2,
INFOVIEW = 3
}