Answered Compile Error Using .Text

chueseman

New member
Joined
Feb 23, 2021
Messages
2
Programming Experience
3-5
I am trying to create a testing Solution, using Visual Studio 2019, (.NET Framework 4.7.2) that will test various small sections of code that will be used in a much larger Solution. The code below in Form1.cs should compile, but does not. I want to derive a string and then send it to textBox1.Text for visual verification.


C#:
using System; using System.Windows.Forms;
string txtout1 = “previously derived string”;;
string txtout = null;
txtout.Text = txtout1; // problem with use of .Text on this line
textBox1.Text += txtout;
The compiler doesn’t like the use of “.Text” in the third line of code and gives the following error.

error CS1061: 'string' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Any thoughts?
 
Last edited by a moderator:
Solution
The computer is not lying to you. txtout does not have a Text member because it is a declared as a string. String's have a Length property, but not a Text property. If you want to change the value of a string, you cannot. You can only reference a new string instead.

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,386
Location
Chesapeake, VA
Programming Experience
10+
The computer is not lying to you. txtout does not have a Text member because it is a declared as a string. String's have a Length property, but not a Text property. If you want to change the value of a string, you cannot. You can only reference a new string instead.
 
Solution
Top Bottom