What are string literals in C#?

CsharpProgrammingServer Side Programming

String literals or constants are enclosed in double quotes "" or with @"". A string contains characters that are similar to character literals: plain characters, escape sequences, and universal characters.

Here are some examples of String Literals −

“Hi, User"
"You’re Welcome, \

The following is an example showing the usage of string literals −

Example

 Live Demo

using System;

namespace Demo {

   class Program {
      static void Main(string[] args) {

         // string
         string str1 ="Hello, World";
         Console.WriteLine(str1);
         // Multi-line string
         string str2 = @"Welcome,
         Hope you are doing great!";
         Console.WriteLine(str2);
      }
   }
}

Output

Hello, World
Welcome,
Hope you are doing great!
raja
Published on 10-Aug-2018 14:14:42
Advertisements