StringBuilder does not contain a definition for Append

Seph 6 Reputation points
2021-08-04T04:25:07.843+00:00

I'm having some error and I'm too much of a noob to figure out how to get around it. It's saying

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

using System;

namespace Working_with_Strings  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
  
StringBuilder myString = new StringBuilder();  
  
            for (int i = 0; i < 100; i++)  
            {  
                myString.Append("--");  
            }  

            Console.WriteLine(myString);  
            Console.ReadLine();  
       }   
 }  

}

It seems that anything I do regarding StringBuilder doesn't work. Even opening a new project and copy/pasting it directly from https://learn.microsoft.com/en-us/dotnet/standard/base-types/stringbuilder it just doesn't work.

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Seph 6 Reputation points
    2021-08-04T19:45:59.333+00:00

    No I didn't do anything outside of just try to use stringbuilder. It works normally in the video I am following, but when I do it it just throws out a bunch of errors and doesn't seem to exist for me.

    When I click on it it brings me to Internal Class StringBuilder, which has nothing.

    namespace Working_with_Strings
    {
        internal class StringBuilder
        {
        }
    }
    
    1 person found this answer helpful.

  2. Sam of Simple Samples 5,571 Reputation points
    2021-08-04T04:39:57.123+00:00

    Are you missing a using directive or an assembly reference?

    Do you have the following at the beginning of your program (file)?

    using System.Text;
    

    If not then add that.


  3. Timon Yang-MSFT 9,606 Reputation points
    2021-08-04T05:54:08.91+00:00

    Did you define a class called StringBuilder yourself?

    120317-1.png

    Hold down the Ctrl key and click on the class to see where the program will jump to?

    Or hover your mouse over this class to see if it is a System.Text.StringBuilder like the picture below:

    120384-2.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  4. Karen Payne MVP 35,596 Reputation points Volunteer Moderator
    2021-08-04T22:04:23.377+00:00

    What happens with using

    System.Text.StringBuilder builder = new StringBuilder();
    builder.Append("Hello");
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.