String Data Type in C# Programming Language

Rumman Ansari   Software Engineer   2019-03-05   5764 Share
☰ Table of Contents

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:-

  1. The String data type is specified to declare a string variable called message. The variable is then assigned a value of "Hello".
  2. 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