How to Add Hyphens in C Sharp

The C# language has several string functions that let you append characters to existing strings. You use the "+=" notation to add a hyphen to a C# string. You use this notation when you want to build a string of characters that you later use to store data to a database or display the information to the user.

Instructions

    • 1

      Open the Visual Studio software from the Microsoft Windows "Start" menu. Open your C# project after VS loads.

    • 2

      Double-click the ".cs" file you want to use to append the hyphen to the string. If you do not already have a string you want to use, the following code shows you how to create a string:

      string mystring = string.Empty;

    • 3

      Append the hyphen to the string. The following code takes the existing string content and appends a hyphen to the text:

      mystring = "some text here";
      mystring += "-";

    • 4

      Display the output. In this example, the output displays "some text here-" in the console. The following code shows you how to display the results:

      System.Console.WriteLine(mystring);

Related Searches:

References

Comments

Related Ads

Featured