Reputation: 11
I have a class named animal
, it have public string name
, species
, and public Byte photoAnimal
.
In another form I create animal named Simba,and i want to set the value of Simba but when I want to set the photoAnimal
I get error. I use filestream
and binaryreader
to read the data, then create byte[] imageData = binary
data from filestream
and binary reader. I cant set the Simba.photoAnimal = imageData
, here's some of my code:
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
Upvotes: 0
Views: 142
Reputation: 9201
The error message means it cannot assign your ImageData
(of type byte[]
) to photoAnimal
, which seems to be of type byte
In your class animal
, change the type of photoAnimal
to an array :
public class animal
{
public byte[] photoAnimal;
}
As a side note, you inverted the naming convention. variables should be in camelCase and classes in UpperCamelCase. Instead of animal Simba = new animal(),
in C# you normally use Animal simba = new Animal()
Upvotes: 1
Reputation: 2700
ImageData is a byte[]. So in the animal class, replace
public Byte photoAnimal
by
public Byte[] photoAnimal.
Upvotes: 7