我现在还是一学生,如有高见请指教!
先把我写的代码贴出来,(为突出重点,就只写能反应需要的了!)
public enum tableNames
{
t_Que_marketCompare_algorithm=0 , //市场比较法
t_que_cost_approach_newLand //成本法,新开发土地
}
foreach (string item in Enum.GetNames(typeof(tableNames)))
{
string usingTable = item;
}
使用方法:
enum
enum通常使用在程序需要表示默认的情况下使用,小弟在此用在需要访问的各个表上,由于需要用到的表是固定的,所以满足条件了!
枚举是一指定的常数,可以给其赋值,也可以不给其赋值,不赋值时,默认从0开始,然后依次加1.不过也可以根据需要获得其他的属性哦,比如偶就获得了所需要的表的名子了,因为
Enum.GetNames(typeof(tableNames))返回的是其名称!其他的你就根据自己的需要来调用了!!!
赋值:tableNames myTable = tableNames.t_Que_marketCompare_algorithm;
转换 int i = Convert.ToInt32(myTable); myTable = (tableNames)2;//用法酷似一种普通类型了!!
foreach
foreach通常用于对数组和集合中的每一个元素进行访问,和for循环比较类似,可以使用break关键字跳出循环,或使用continue关键字进入循环的下一轮跌代,只是需要注意的是他的类型和标志符都是必须的,也就是说,string item; foreach ( item in Enum.GetNames(typeof(tableNames))){}这样是会报错的,必须写成foreach (string item in Enum.GetNames(typeof(tableNames)))!!!!
顺便为了防止忘记
把我写的结构体数组,及其使用也放在这吧,
结构体
public struct usingCase
{
public string groundID;
public string caseId;
public int year;
public int season;
public string strPurpose;
}
结构体数组:
public static usingCase[] caseCollection = new usingCase[1000];
使用:
public usingCase myUsingCase=new usingCase();
赋值的时候就是和通常的成员调用一样了,如: myUsingCase.groundID="wonderfu!";
caseCollection[number]=myUsingCase;
和通常的使用就没有啥区别了!