namespace ConsoleApplication5 { class Program { static void Main(string[] args) { AA A= new AA() { MyProperty = 1, SSS = "dd", jj = 23 }; PropertyInfo[] pInfos =A.GetType().GetProperties(); foreach (var item in pInfos) { Console.WriteLine(item.Name);
} Console.Read(); } } class AA { public int MyProperty { get; set; } public string SSS { get; set; } public int jj { get; set; } } }
如题 可扩展 我再添加 100个属性呢 不能 再改程序 添加100个FOR循环吧
类似下面??string[] color = {"红","黄","蓝"}; string[] size = {"大","中","小"}; string[] type = {"1","2","3"}; string[] result= new string[color.count()*size.count()*type.count()]; int i = 0; foreach(var t1 in color) { foreach(var t2 in size ) { foreach(var t3 in type ) { result[i++] = t1 + t2 + t3; ....... } } }
表 property 列 id name 用来存 颜色 大小 等 任何 属性值 属性多少不限定 可随时修改添加 表 p_value 列 id name p_id 跟 property 关联 用来 存储 颜色等属性值的元素 比如颜色的红黄绿 等 元素值多少不限定 可随时修改 添加 想要的结果 就是5楼 那样 的循环遍历出来 当然顺序 不必 一样
有什么问题呢?
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
AA A= new AA() { MyProperty = 1, SSS = "dd", jj = 23 };
PropertyInfo[] pInfos =A.GetType().GetProperties();
foreach (var item in pInfos)
{
Console.WriteLine(item.Name);
}
Console.Read();
}
}
class AA
{
public int MyProperty { get; set; }
public string SSS { get; set; }
public int jj { get; set; }
}
}
string[] size = {"大","中","小"};
string[] type = {"1","2","3"};
string[] result= new string[color.count()*size.count()*type.count()];
int i = 0;
foreach(var t1 in color)
{
foreach(var t2 in size )
{
foreach(var t3 in type )
{
result[i++] = t1 + t2 + t3;
.......
}
}
}
表 p_value 列 id name p_id 跟 property 关联 用来 存储 颜色等属性值的元素 比如颜色的红黄绿 等 元素值多少不限定 可随时修改 添加 想要的结果 就是5楼 那样 的循环遍历出来 当然顺序 不必 一样
感谢
foren_whb
(丰云)
给我指明了方向~