c# - 如何设置自定义类的反射数组的行

标签 c# asp.net arrays reflection

我如何通过反射设置数组的第一行和第二行,我有 将我的值设置为自定义对象,但我无法将其分配给数组,因为第一行和第二行为空

var reflectedArray= Array.CreateInstance(classNameType, 2);

Object itemOfArrayTemp = Activator.CreateInstance(classNameType);

reflectedArray[0] = myValue1;

reflectedArray[1] = myValue2;

错误是:

Cannot apply indexing with [] to an expression of type 'Array'

最佳答案

您需要在reflectedArray上使用SetValue方法

reflectedArray.SetValue(value1,0);
reflectedArray.SetValue(value2, 1);

关于c# - 如何设置自定义类的反射数组的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45051290/

相关文章:

c# - 一种使用反射访问所有资源值的方法

c# - WPF 数据网格 : converter and StringFormat

c# - SharePoint 2013 更新面板空闲

c# - ExecuteStoreQuery 将参数传递给 SQL 语句

c++ - 在c++中的函数中传递可变大小的多维数组

arrays - 在 C 中更改数组值会产生 "undefined reference to ' memset'"

c# - MVVM 分离程序集 Visual Studio : What should I choose as the project types?

c# - 为什么此按钮在 ASP.NET MVC CSS 中显示在表格上方而不是下方

asp.net - ViewResult() 和 ActionResult() 之间的区别

Javascript 嵌套数组问题