how to make a cast in c#
//If you want to make your own cast for your struct or class you
//can overload an operator. Note that you can't make a cast
//if your your target class is in inheritence with yours.
// This is if you want to manually type out (MyType)b. This is recommened
// if your cast can fail.
public static explicit operator MyType(byte[] b)
{
MyType m = new MyType();
m = MagicToConvertByteToMytype(b);
return m;
}
// This is if you want to do it automatically.
// This is recommened if your cast is defananlty safe.
public static implicit operator byte[](MyType m)
{
return m.ToBytes();
}