locked
How to define '+' operator's meaning for Of Clause types? RRS feed

  • Question

  • User-1976290245 posted

    Hi,

    i have a simple code just have a look

    Partial Class OfClause
    Inherits System.Web.UI.Page

    End Class
    Public Class sum(Of type)

    Protected Function getSum(ByVal num1 As type, ByVal num2 As type) As type

    Dim result As type
    result = num1 + num2


    End Function

    End Class

    Partial Class OfClause
        Inherits System.Web.UI.Page

    End Class
    Public Class sum(Of type)

        Protected Function getSum(ByVal num1 As type, ByVal num2 As type) As type

            Dim result As type
            result = num1 + num2


        End Function

    End Class
    When i add num1 and num2 as above, compiler gave error that -- Operator + is not defined for types "type" and "type".

    How to define the meaning of '+' or any other operator in such situations?

    Thanks

    Tuesday, April 20, 2010 8:48 PM

Answers

  • User-573138384 posted

    You have two questions. One is related to keyword and the other is with operator. I believe you understood the 'Of' at least the basic. Now when you speak about operator, the operator have action and expression(s) which will be applied to specific type(As you understand we can specify a type with of in generics).

    Have a look at + operator. When you look for arithmetic action with + operator, it can be applicable to numeric and string only. In your example you have mentioned as Type. A Type can be anything it can be object, xml, a datattaable anything. And operator can be applied on specific types, the compiler is not accepting.

    Get good info on operators

    http://msdn.microsoft.com/en-us/library/952c4thw.aspx

    To understand the basic, have a look at one operator specified in one action. The following is + operator with Arithmetic action

    http://msdn.microsoft.com/en-us/library/9c5t70w2.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 21, 2010 6:25 AM

All replies

  • User-577741185 posted

    You can't add a "type" but you can add a number. Change "Type" to Integer.

    Tuesday, April 20, 2010 10:27 PM
  • User-1976290245 posted

    Then what is the use of Of Clause? As i think Of operator is for dynamically setting the type.Is'nt it? 

    Tuesday, April 20, 2010 11:08 PM
  • User-1976290245 posted

    One thing plz tell me how to add another person's reply(of course some part of the reply) to specify my query on that part , in my reply. 

    Tuesday, April 20, 2010 11:12 PM
  • User-577741185 posted

    I don't know about your other question, but your second one - do you mean how to "quote" someone? like this?

    One thing plz tell me how to add another person's reply(of course some part of the reply) to specify my query on that part , in my reply. 

    You need to click the reply button on the top of the person's post. Then that person's post will appear in a grayed-out box. Highlight the part you want to quote, then click the "Quote" button.


    Tuesday, April 20, 2010 11:21 PM
  • User-1976290245 posted

    Highlight the part you want to quote, then click the "Quote" button.
     

    ok thanks.

    but please tell me where are you getting confused about my problem?i will try to explain that.

    Tuesday, April 20, 2010 11:26 PM
  • User-577741185 posted

    but please tell me where are you getting confused about my problem?i will try to explain that.

    I'm not confused - I just don't know the answer at this point.

    Don't worry, I'm sure someone more knowledgeable will come around and explain it to you :)

    Tuesday, April 20, 2010 11:33 PM
  • User-1976290245 posted

    ok thanks 

    Tuesday, April 20, 2010 11:48 PM
  • User-1976290245 posted

    HI everyone,

    is no one  interested in "Of"  keyword and its use in Class and Functions? can anyone help  me? 

    Thanks

    Wednesday, April 21, 2010 3:08 AM
  • User-573138384 posted

    Of is used to identify the type parameter on generic class. Its mostly used when we deal with generics. You can get more info from msdn

    http://msdn.microsoft.com/en-us/library/067b2z78%28v=VS.80%29.aspx


    Wednesday, April 21, 2010 3:22 AM
  • User-1976290245 posted

    link you provided did'nt helped me.

    This i understood that Of is used to identify Type on Generic Class. Then how to define the meaning of  operators (like +,-,*,/ etc) to these types.  

    Wednesday, April 21, 2010 5:42 AM
  • User-573138384 posted

    You have two questions. One is related to keyword and the other is with operator. I believe you understood the 'Of' at least the basic. Now when you speak about operator, the operator have action and expression(s) which will be applied to specific type(As you understand we can specify a type with of in generics).

    Have a look at + operator. When you look for arithmetic action with + operator, it can be applicable to numeric and string only. In your example you have mentioned as Type. A Type can be anything it can be object, xml, a datattaable anything. And operator can be applied on specific types, the compiler is not accepting.

    Get good info on operators

    http://msdn.microsoft.com/en-us/library/952c4thw.aspx

    To understand the basic, have a look at one operator specified in one action. The following is + operator with Arithmetic action

    http://msdn.microsoft.com/en-us/library/9c5t70w2.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 21, 2010 6:25 AM