Mastering the String Data Type in C# Programming: An In-Depth Guide
☰Fullscreen
Table of Content:
String
A String data type is used to work with String values. In C#, the datatype is denoted by the keyword 'String'. Below is an example of this datatype.
In our example, we will define a String variable called 'message.' We will then assign a String value to the variable and then display it accordingly.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoApplication { class program { static void Main(string[] args) { String message="Hello"; Console.Write(message); Console.ReadKey(); } } }
Code Explanation:-
- The String data type is specified to declare a string variable called message. The variable is then assigned a value of "Hello".
- Finally, the console.write function is used to display the string value to the console.
If the above code is entered properly and the program is executed successfully, the output will be displayed.
Output:
Hello
From the output, you can clearly see that the String variable called message was displayed in the console