C# – convert from int to byte

bytec++type-conversion

System.ArgumentException: Object must be of type Int32.

in this code:

MyBO target = new MyBO() { x1 = 20 };

In MyBO i have an attribute: public byte x1 {get; set;}

What's wrong? I tried with MyBO target = new MyBO() { x1 = (byte)20 }; but i got the same error.
Please help.

Thanks!

Best Solution

MYBO target=new MyBO();
target.x1=Convert.ToByte(20);