Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将字符串赋给c中类类型的数组#_C# - Fatal编程技术网

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]
您只分配一个给定大小的新数组,但是该数组到目前为止没有任何内容。你只是说你需要一些记忆,但不是为了什么