Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

Character Constants ต่างจาก String Literals ใน C# อย่างไร

Character Constants

Character literals ล้อมรอบด้วย single quotes เช่น 'x' เก็บในตัวแปร char ได้ character literal อาจเป็น plain character ('x'), escape sequence ('\t'), หรือ universal character ('\u02C0')

บางตัวอักษรใน C# นำหน้าด้วย backslash มีความหมายพิเศษ เช่น newline (\n) หรือ tab (\t)

ตัวอย่าง

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

ผลลัพธ์

Welcome to the website

String Literals

String literals ล้อมรอบด้วย double quotes "" หรือ @"" สตริงประกอบด้วยตัวอักษรคล้าย character literals: plain characters, escape sequences, universal characters