原来问过一次,我问得乱,结果也看不出各位回答的是哪个问题了。。散分,结贴,重新再问一下问题再说一下:
public class a
{
public static string aa[3]={"0","1","2"};
}
public class b
{
public static string bb[5]={"3","4","5","6","7"};
} 请问如何在别的地方动态获得整个数组b的值呢?其中类型已经确定。
既
public class xx
{
public void xxx(string xxxx)
{
string[] c;
c = 这时要根据参数xxxx的值来确定c指向a.aa还是b.bb,就是不知道这个地方的代码怎么写。 //这里jeremyyang824的写法是
//c = ((string[])_a.GetType().GetField("b", BindingFlags.NonPublic ¦BindingFlags.Instance).GetValue(_a));
//petshop的写法好像应该是PetShop.DALFactory里的
//public static PetShop.IDAL.ICategory CreateCategory() {
// string className = path + ".Category";
// return (PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className);
//}
} } 项目中只有一个class a,只有一个class xx。请不必考虑重复的问题。 有的朋友说
public class xx :a
但是这样能得到aa的值,不能得到b.bb的值。这样应该是不可行的吧。
public class a
{
public static string aa[3]={"0","1","2"};
}
public class b
{
public static string bb[5]={"3","4","5","6","7"};
} 请问如何在别的地方动态获得整个数组b的值呢?其中类型已经确定。
既
public class xx
{
public void xxx(string xxxx)
{
string[] c;
c = 这时要根据参数xxxx的值来确定c指向a.aa还是b.bb,就是不知道这个地方的代码怎么写。 //这里jeremyyang824的写法是
//c = ((string[])_a.GetType().GetField("b", BindingFlags.NonPublic ¦BindingFlags.Instance).GetValue(_a));
//petshop的写法好像应该是PetShop.DALFactory里的
//public static PetShop.IDAL.ICategory CreateCategory() {
// string className = path + ".Category";
// return (PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className);
//}
} } 项目中只有一个class a,只有一个class xx。请不必考虑重复的问题。 有的朋友说
public class xx :a
但是这样能得到aa的值,不能得到b.bb的值。这样应该是不可行的吧。
解决方案 »
- 一个关于文件下载的问题,很奇怪!!!
- 如何让自己的控件安装后在VS2005的工具栏上显示?
- winform 管理端向客户端传递消息问题
- 100分-WMI修改IP,我还差了什么步骤
- 如果RichTextBox绑定一个字段,失去焦点后字体的格式都会丢失,这是什么原因?
- 这样的类型转换该怎么解决呢?
- 未来报表发展的新方向,用word设计报表,只要懂得word就可以设计报表
- 帮分析下,直接调试.net windows service无法将数据导入到数据库
- 求助:经常出现的.NET编译错误的原因是什么
- 怎么样检测word或者是excel的版本?
- C#链接数据库时提示:找不到可安装的ISAM
- net.mail发送邮件在服务器上失败
using System.Collections.Generic;
using System.Text;
using System.Reflection;namespace ReflectionTest
{
class Program
{
static void Main(string[] args)
{
xx.xxx("ReflectionTest.a");
show(); Console.WriteLine("-----"); xx.xxx("ReflectionTest.b");
show(); Console.ReadLine();
} private static void show()
{
foreach (string x in xx.c)
{
Console.WriteLine(x);
}
}
}
public class a
{
public static string[] ss = new string[] { "0", "1", "2" };
}
public class b
{
public static string[] ss = new string[] { "3", "4", "5", "6", "7" };
} public class xx
{
public static string[] c; public static void xxx(string xxxx)
{
FieldInfo t = Assembly.Load("ReflectionTest").GetType(xxxx).GetField("ss");
c = (string[])t.GetValue(null);
}
}
}