0 c#
我有一个名为类animal,它有public string name,species和public Byte photoAnimal.
在另一种形式我创建名为Simba的动物,我想设置Simba的值,但是当我想设置photoAnimal我得到的错误.我使用filestream和binaryreader读取数据,然后create byte[] imageData = binary从filestream二进制读取器读取数据.我不能设置Simba.photoAnimal = imageData,这是我的一些代码:
animal Simba = new animal();
string fileName = textBox5.Text;
byte[] ImageData;
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
br = new BinaryReader(fs);
ImageData = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
Simba.name = textBox1.Text;
Simba.species = textBox2.Text;
Simba.photoAnimal = ImageData; // error
Run Code Online (Sandbox Code Playgroud)
ImageData是一个byte [].所以在动物类中,替换
public Byte photoAnimal
Run Code Online (Sandbox Code Playgroud)
通过
public Byte[] photoAnimal.
Run Code Online (Sandbox Code Playgroud)