zoukankan      html  css  js  c++  java
  • String @ C#

     

    The string type represents a string of Unicode characters. string is an alias for System.String in the .NET Framework.

    Although string is a reference type, the equality operators (== and !=) are defined to compare the values of string objects, not references (7.9.7 String equality operators). This makes testing for string equality more intuitive.

    string a = "hello";
    string b = "h";
    b += "ello"; // append to b
    Console.WriteLine( a == b );          // output: True -- same value
    Console.WriteLine( (object)a == b );  // False -- different objects

    The + operator concatenates strings:

    string a = "good " + "morning";

    The [] operator accesses individual characters of a string:

    char x = "test"[2];  // x = 's';

    String literals are of type string and can be written in two forms, quoted and @-quoted. Quoted string literals are enclosed in double quotation marks ("):

    "good morning"  // a string literal

    and can contain any character literal, including escape sequences:

    string a = "\\\u0066\n";  // backslash, letter f, new line
    Note   The escape code \udddd (where dddd is a four-digit number) represents the Unicode character U+dddd. Eight-digit Unicode escape codes are also recognized: \udddd\udddd.

    @-quoted string literals start with @ and are enclosed in double quotation marks. For example:

    @"good morning"  // a string literal

    The advantage of @-quoting is that escape sequences are not processed, which makes it easy to write, for example, a fully qualified file name:

    @"c:\Docs\Source\a.txt"  // rather than "c:\\Docs\\Source\\a.txt"

    To include a double quotation mark in an @-quoted string, double it:

    @"""Ahoy!"" cried the captain." // "Ahoy!" cried the captain.

    Another use of the @ symbol is to use referenced (/reference) identifiers that happen to be C# keywords. For more information, see 2.4.2 Identifiers.

    Example

    // keyword_string.cs
    using System;
    class test 
    {
       public static void Main( String[] args ) 
       {
          string a = "\u0068ello ";
          string b = "world";
          Console.WriteLine( a + b );
          Console.WriteLine( a + b == "hello world" );
       }
    }

    Output

    hello world
    True

     

    签名内容 FuckMe 123123123!
  • 相关阅读:
    「赛后总结」Codeforces Round #680 (Div. 2)
    雲雀
    「题解」洛谷 P1494 [国家集训队]小Z的袜子
    NOIP 2020 退役记
    任务查询系统「主席树+差分」
    组合「欧拉路」
    AtCoder 123 Triangle「思维题」
    旅行(加强版)「基环树」
    一个简单的询问「莫队」
    [HNOI2012]永无乡「线段树合并」
  • 原文地址:https://www.cnblogs.com/imcooler/p/1431436.html
Copyright © 2011-2022 走看看