String Type - CSharp Language Basics

CSharp examples for Language Basics:string

Introduction

C#'s string type (aliasing the System.String type) represents an immutable sequence of Unicode characters.

A string literal is specified inside double quotes:

string a = "Heat";

string is a reference type, rather than a value type.

Its equality operators, however, follow value-type semantics:

Demo Code

using System;/*from www.j  ava  2s.c om*/
class Test
{
   static void Main(){
      string a = "test";
      string b = "test";
      Console.Write (a == b);  // True
   }
}

Result

The escape sequences that are valid for char literals also work inside strings:

Demo Code

using System;//  w w  w.  j  av  a 2  s  .  co m
class Test
{
static void Main(){
      string a = "Here's a tab:\t";
      Console.WriteLine (a);
}
}

Result


Related Tutorials