c# - Operator '!' cannot be applied to operand of type long -


i doing conversion of old vb code c#. getting error when converting couple of properties.

"operator '!' cannot applied operand of type long"

this vb code looks , hoping this.

public property value() integer             if (me.m_value < 32768)             return me.m_value         else             return -32768 + (me.m_value - 32768)         end if     end     set(byval plcvalue integer)         me.m_value = plcvalue     end set end property  public property b0() boolean             if ((me.m_value , &h1&) = &h1&)             return true         else             return false         end if     end     set(byval state boolean)         if (state = true)             me.m_value = me.m_value or &h1&         else             me.m_value = me.m_value , (not &h1&)         end if     end set end property public property b1() boolean             if ((me.m_value , &h2&) = &h2&)             return true         else             return false         end if     end     set(byval state boolean)         if (state = true)             me.m_value = me.m_value or &h2&         else             me.m_value = me.m_value , (not &h2&)         end if     end set end property 

this looks when converting it. both set conditions getting error. or | can change casting (int) , error goes away not sure on else condition how adjust that?

public int value     {                 {             if ((_value < 32768))             {                 return _value;             }             else             {                 return -32768 + (_value - 32768);             }         }         set { _value = value; }     }      public bool b0     {                 {             if (((_value & 0x1l) == 0x1l))             {                 return true;             }             else             {                 return false;             }         }         set         {             if ((value == true))             {                 _value = _value | 0x1l;             }             else             {                                     _value = _value & (!0x1l);              }         }     }     public bool b1     {                 {             if (((_value & 0x2l) == 0x2l))             {                 return true;             }             else             {                 return false;             }         }         set         {             if ((value == true))             {                 _value = _value | 0x2l;             }             else             {                 _value = _value & (!0x2l);             }         }     } 

thanks!

complete code, correct:

public int value     {                 {             if ((_value < 32768))             {                 return _value;             }             else             {                 return -32768 + (_value - 32768);             }         }         set { _value = value; }     }      public bool b0     {                 {             if (((_value & 0x1) == 0x1))             {                 return true;             }             else             {                 return false;             }         }         set         {             if ((value == true))             {                 _value = _value | 0x1;             }             else             {                                     _value = _value & (~0x1);              }         }     }     public bool b1     {                 {             if (((_value & 0x2) == 0x2))             {                 return true;             }             else             {                 return false;             }         }         set         {             if ((value == true))             {                 _value = _value | 0x2;             }             else             {                 _value = _value & (~0x2);             }         }     } 

as pointed out in comment , confirmed @mataps link, not on numerical value should interpreted bitwise negate ~ in c#. also, dropped l literal everywhere, because value of type int, not long, compiler doesn't compain doing bitwise operations on different types (int , long)


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -