Character constants vs String literals in C#


Character constants

Character literals are enclosed in single quotes. For example, 'x' and can be stored in a simple variable of char type. A character literal can be a plain character (such as 'x'), an escape sequence (such as '\t'), or a universal character (such as '\u02C0').

Certain characters in C# are preceded by a backslash. They have special meaning and they are used to represent like newline (
) or tab (\t).

Example

 Live Demo

using System;
namespace Demo {
   class MyApplication {
      static void Main(string[] args) {
         Console.WriteLine("Welcome\t to the website

");          Console.ReadLine();       }    } }

Output

Welcome to the website

String literals

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.

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Jun-2020

329 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements