Operand Issue


Apr 12, 2013
Programming Experience
I am following a course that I had previously taken to refresh my memory. I have an issue with C#. The lesson say's to use is this code in a Repeater:

        <a id="A1" href=<%#"~/MemberPages/viewprofile.aspx?UserId=" & Eval("UserId").ToString %> runat="server" >
                        <%#Eval("UserName")%></a><br />

Here is the error message.
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0019: Operator '&' cannot be applied to operands of type 'string' and 'method group'

I tried replacing the & with + and got the same thing. Any help on this?
I changed it to this:

        <a id="A1" href=<%#"~/MemberPages/viewprofile.aspx?UserId=" + Eval("UserId").ToString() %> runat="server" >
                        <%#Eval("UserName")%></a><br />

I replaced the & with + and added () to ToString.
Your code from post #1 would be valid VB code, so that's probably what it is. In VB, you don't have to include parentheses on a method call if there are arguments and & is the string concatenation operator. In C#, using a method name without parentheses creates a delegate to that method, for which you use AddressOf in VB, and + is the string concatenation operator. You might want to ensure that you're using C# source code from wherever you're getting it or else you're going to have to convert from VB to C# every time.

Latest posts

Top Bottom