最終更新:2012-01-07 (土) 16:33:36 (4486d)  

リテラル
Top / リテラル

「10」や「4.56」というように、直接ソースファイル中に値が書かれた定数のこと

C♯

  • リテラル文字列? ("hello world!")
    • エスケープシーケンスが有効
  • 逐語的リテラル文字列? ( @"hello world!")
    • エスケープシーケンスが無効
string a = "hello, world";                  // hello, world
string b = @"hello, world";               // hello, world
string c = "hello \t world";               // hello     world
string d = @"hello \t world";               // hello \t world
string e = "Joe said \"Hello\" to me";      // Joe said "Hello" to me
string f = @"Joe said ""Hello"" to me";   // Joe said "Hello" to me
string g = "\\\\server\\share\\file.txt";   // \\server\share\file.txt
string h = @"\\server\share\file.txt";      // \\server\share\file.txt
string i = "one\r\ntwo\r\nthree";
string j = @"one
two
three";