Home > Software engineering >  Error: CS0019: Operator ' ' cannot be applied to operands of type 'TextBox' and
Error: CS0019: Operator ' ' cannot be applied to operands of type 'TextBox' and

Time:05-20

So I'm working on a application that ask for age, weight, height, sex, name and after clicking a button makes a info.txt and writes the information given by the user

WPF:


<TextBox Margin="0,15,0,0" x:Name="txtName" Width="300" FontSize="18" materialDesign:HintAssist.Hint="Enter name" BorderThickness="2" BorderBrush="{DynamicResource MaterialDesignDivider}"  Style="{StaticResource MaterialDesignOutlinedTextBox}" />

<TextBox Margin="0,15,0,0" x:Name="txtWeight" Width="300" FontSize="18" materialDesign:HintAssist.Hint="Enter Weight (KG)" BorderThickness="2" BorderBrush="{DynamicResource MaterialDesignDivider}"  Style="{StaticResource MaterialDesignOutlinedTextBox}" />

<TextBox Margin="0,15,0,0" x:Name="txtHeight" Width="300" FontSize="18" materialDesign:HintAssist.Hint="Enter Height (CM)" BorderThickness="2" BorderBrush="{DynamicResource MaterialDesignDivider}"  Style="{StaticResource MaterialDesignOutlinedTextBox}" />

<TextBox Margin="0,15,0,0" x:Name="txtSex" Width="300" FontSize="18" materialDesign:HintAssist.Hint="Enter Sex (Male / Female)" BorderThickness="2" BorderBrush="{DynamicResource MaterialDesignDivider}"  Style="{StaticResource MaterialDesignOutlinedTextBox}" />

<Button  Margin="0,50,0,0" x:Name="loginBtn" Style="{StaticResource MaterialDesignFlatMidBgButton}" materialDesign:ShadowAssist.ShadowDepth="Depth0" Height="53" Width="300" materialDesign:ButtonAssist.CornerRadius="10" FontSize="18" Content="Create Profile" Click="doLogin"></Button> 

C#

public void doLogin(object sender, RoutedEventArgs e)
        {
            try
            {
                TextWriter tw = new StreamWriter("info.txt", true);
                tw.WriteLine(txtAge   txtWeight   txtHeight   txtSex   txtName);
                tw.Close();

            }catch(Exception myE)
            {
                Console.Write(myE);
            }

            Console.Read();
        }

Error

Error: CS0019: Operator ' ' cannot be applied to operands of type 'TextBox' and 'TextBox'

The error code is from the C# code

CodePudding user response:

You need to access the text atribute of the TextBoxes not the TextBox themselves.

tw.WriteLine(txtAge.Text   txtWeight.Text   txtHeight.Text   txtSex.Text   txtName.Text);
  • Related