C# 将字符串赋给c中类类型的数组#
我有一个类,其中我定义了两个变量C# 将字符串赋给c中类类型的数组#,c#,C#,我有一个类,其中我定义了两个变量 public class attachment_type { string filename; int cnt; } 在第二个类中,我想为文件名分配字符串值。在已经存在的代码中,他们创建了类类型的数组 public class mainApp { attachment_type[] at = new attachment_type[dt.rows.count]; at[0].filename = "test File" } 我无法做
public class attachment_type
{
string filename;
int cnt;
}
在第二个类中,我想为文件名分配字符串值。在已经存在的代码中,他们创建了类类型的数组
public class mainApp
{
attachment_type[] at = new attachment_type[dt.rows.count];
at[0].filename = "test File"
}
我无法做到以上几点。错误出现在[0]的第行代码>
对象引用未设置为对象的实例
必须为数组中的每个条目分配一个新的类实例:
public class mainApp
{
attachment_type[] at = new attachment_type[dt.rows.count];
at[0] = new attachment_type();
at[0].filename = "test File"
}
带有attachment_type[]at=新的attachment_type[dt.rows.count]
您只分配一个给定大小的新数组,但是该数组到目前为止没有任何内容。你只是说你需要一些记忆,但不是为了什么