define an operator on class


hi guys,

i want define operators in class named student.in of them +,*,- there no problem must define >=,<= , != too! tried write code last ones there errors.

this class code:

      class student      {            public int _input1;          public int _input2;          public static int operator +(student c1, student c2)          {              return c1._input1 + c2._input2;          }          public static int operator -(student c1, student c2)          {              return c1._input1 - c2._input2;          }          public static int operator *(student c1, student c2)          {              return c1._input1 * c2._input2;          }                }  

can define other operators or no? please me

 


sincerely,skywolf

of course can define. see below. 

class student  {        public int _input1;      public int _input2;                public static int operator +(student c1, student c2)      {          return c1._input1 + c2._input2;      }      public static int operator -(student c1, student c2)      {          return c1._input1 - c2._input2;      }      public static int operator *(student c1, student c2)      {          return c1._input1 * c2._input2;      }        public static bool  operator >(student c1, student c2)      {          return c1._input1 > c2._input2;      }        public static bool operator <(student c1, student c2)      {          return c1._input1 < c2._input2;      }        public static bool operator >=(student c1, student c2)      {          return c1._input1 >= c2._input2;      }        public static bool operator <=(student c1, student c2)      {          return c1._input1 <= c2._input2;      }        public static bool operator ==(student c1, student c2)      {          return c1._input1 == c2._input2;      }        public static bool operator !=(student c1, student c2)      {          return c1._input1 != c2._input2;      }  }

 


please mark post answer if solved problem. happy programming!


Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user