Results 1 to 3 of 3

Thread: C# operator...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    Denmark
    Posts
    67

    C# operator...

    Code:
            private void Form1_MouseClick(object sender, MouseEventArgs e)
            {
                label1.Text = "x:" && MousePosition.X.ToString();
            }
    i get an error saying that Error, Operator '&&' cannot be applied to operands of type 'string' and 'string'

    I know that in VB.net i can just type "string" & something.text & "string"
    what am i doing wrong in C# ?

    how can i get the "x:" and the mouseposition to stand on one line ? :S
    Last edited by RoflJOE; Nov 14th, 2006 at 07:16 PM.

  2. #2
    Lively Member
    Join Date
    Oct 2006
    Posts
    71

    Re: C# operator...

    Use the "+" operator to concatenate strings. "&&" is the logical "and" operator.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: C# operator...

    In VB.NET the '&' is the string concatenation operator. In C# the '&' and '&&' are boolean and bitwise operators, like 'And' and 'AndAlso' in VB.NET. The string concatenation operator in C# is '+'. Note that '+' will also concatenate two strings in VB.NET.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width