none
Error CS0019_Operator '&' cannot be applied to operands of type 'string' and 'string' RRS feed

  • Question

  • Hov do i fix this i am a beginner please help.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace VB2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("Hello " & txtName2.Text,
                            "Hello " & txtName2.Text);
            }

            private void btnOK_Click(object sender, EventArgs e)
            {
                txtName2.Text = "Hello " & txtName2.Text;
            }

            private void btnExit_Click(object sender, EventArgs e)
            {

            }
        }
    }


    • Edited by dds124 Wednesday, November 15, 2017 7:45 PM
    Wednesday, November 15, 2017 7:43 PM

All replies

  • In C# use '+' instead of '&'.
    • Proposed as answer by Ante Meridian Wednesday, November 15, 2017 10:37 PM
    Wednesday, November 15, 2017 8:41 PM
  • Hello dds124,

    Do you have anything to update?  If you already have got the useful solution from there, you could close the thread by marking the useful reply as answer, This can be beneficial to other community members reading this thread. Thanks a lot.

    Sincerely,
    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, November 26, 2017 11:47 AM
    Moderator