我有一個名爲animal
的類,它具有public string name
,species
和public Byte photoAnimal
。錯誤不能將類型byte []隱含轉換爲字節
在另一種形式中,我創建了一個名爲Simba的動物,我想設置Simba的值,但是當我想設置photoAnimal
時出現錯誤。我用filestream
和binaryreader
來讀取數據,然後用filestream
和二進制讀取器得到create byte[] imageData = binary
數據。我不能設置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
編譯器錯誤告訴你什麼是錯的。當你將'byte []'賦值給'byte'變量時,你期望發生什麼? –