Char 結構

定義

以UTF-16程式代碼單位表示字元。

public value class char : IComparable, IComparable<char>, IConvertible, IEquatable<char>
public value class char : IComparable<char>, IConvertible, IEquatable<char>, IParsable<char>, ISpanParsable<char>, IUtf8SpanParsable<char>, System::Numerics::IAdditionOperators<char, char, char>, System::Numerics::IAdditiveIdentity<char, char>, System::Numerics::IBinaryInteger<char>, System::Numerics::IBinaryNumber<char>, System::Numerics::IBitwiseOperators<char, char, char>, System::Numerics::IComparisonOperators<char, char, bool>, System::Numerics::IDecrementOperators<char>, System::Numerics::IDivisionOperators<char, char, char>, System::Numerics::IEqualityOperators<char, char, bool>, System::Numerics::IIncrementOperators<char>, System::Numerics::IMinMaxValue<char>, System::Numerics::IModulusOperators<char, char, char>, System::Numerics::IMultiplicativeIdentity<char, char>, System::Numerics::IMultiplyOperators<char, char, char>, System::Numerics::INumber<char>, System::Numerics::INumberBase<char>, System::Numerics::IShiftOperators<char, int, char>, System::Numerics::ISubtractionOperators<char, char, char>, System::Numerics::IUnaryNegationOperators<char, char>, System::Numerics::IUnaryPlusOperators<char, char>, System::Numerics::IUnsignedNumber<char>
public value class char : IComparable, IComparable<char>, IConvertible, IEquatable<char>, ISpanFormattable
public value class char : IComparable<char>, IConvertible, IEquatable<char>, IParsable<char>, ISpanParsable<char>, System::Numerics::IAdditionOperators<char, char, char>, System::Numerics::IAdditiveIdentity<char, char>, System::Numerics::IBinaryInteger<char>, System::Numerics::IBinaryNumber<char>, System::Numerics::IBitwiseOperators<char, char, char>, System::Numerics::IComparisonOperators<char, char, bool>, System::Numerics::IDecrementOperators<char>, System::Numerics::IDivisionOperators<char, char, char>, System::Numerics::IEqualityOperators<char, char, bool>, System::Numerics::IIncrementOperators<char>, System::Numerics::IMinMaxValue<char>, System::Numerics::IModulusOperators<char, char, char>, System::Numerics::IMultiplicativeIdentity<char, char>, System::Numerics::IMultiplyOperators<char, char, char>, System::Numerics::INumber<char>, System::Numerics::INumberBase<char>, System::Numerics::IShiftOperators<char, int, char>, System::Numerics::ISubtractionOperators<char, char, char>, System::Numerics::IUnaryNegationOperators<char, char>, System::Numerics::IUnaryPlusOperators<char, char>, System::Numerics::IUnsignedNumber<char>
public value class char : IComparable, IConvertible
public value class char : IComparable, IComparable<char>, IEquatable<char>
public struct Char : IComparable, IComparable<char>, IConvertible, IEquatable<char>
public readonly struct Char : IComparable<char>, IConvertible, IEquatable<char>, IParsable<char>, ISpanParsable<char>, IUtf8SpanParsable<char>, System.Numerics.IAdditionOperators<char,char,char>, System.Numerics.IAdditiveIdentity<char,char>, System.Numerics.IBinaryInteger<char>, System.Numerics.IBinaryNumber<char>, System.Numerics.IBitwiseOperators<char,char,char>, System.Numerics.IComparisonOperators<char,char,bool>, System.Numerics.IDecrementOperators<char>, System.Numerics.IDivisionOperators<char,char,char>, System.Numerics.IEqualityOperators<char,char,bool>, System.Numerics.IIncrementOperators<char>, System.Numerics.IMinMaxValue<char>, System.Numerics.IModulusOperators<char,char,char>, System.Numerics.IMultiplicativeIdentity<char,char>, System.Numerics.IMultiplyOperators<char,char,char>, System.Numerics.INumber<char>, System.Numerics.INumberBase<char>, System.Numerics.IShiftOperators<char,int,char>, System.Numerics.ISubtractionOperators<char,char,char>, System.Numerics.IUnaryNegationOperators<char,char>, System.Numerics.IUnaryPlusOperators<char,char>, System.Numerics.IUnsignedNumber<char>
public readonly struct Char : IComparable, IComparable<char>, IConvertible, IEquatable<char>
public readonly struct Char : IComparable, IComparable<char>, IConvertible, IEquatable<char>, ISpanFormattable
public readonly struct Char : IComparable<char>, IConvertible, IEquatable<char>, IParsable<char>, ISpanParsable<char>, System.Numerics.IAdditionOperators<char,char,char>, System.Numerics.IAdditiveIdentity<char,char>, System.Numerics.IBinaryInteger<char>, System.Numerics.IBinaryNumber<char>, System.Numerics.IBitwiseOperators<char,char,char>, System.Numerics.IComparisonOperators<char,char,bool>, System.Numerics.IDecrementOperators<char>, System.Numerics.IDivisionOperators<char,char,char>, System.Numerics.IEqualityOperators<char,char,bool>, System.Numerics.IIncrementOperators<char>, System.Numerics.IMinMaxValue<char>, System.Numerics.IModulusOperators<char,char,char>, System.Numerics.IMultiplicativeIdentity<char,char>, System.Numerics.IMultiplyOperators<char,char,char>, System.Numerics.INumber<char>, System.Numerics.INumberBase<char>, System.Numerics.IShiftOperators<char,int,char>, System.Numerics.ISubtractionOperators<char,char,char>, System.Numerics.IUnaryNegationOperators<char,char>, System.Numerics.IUnaryPlusOperators<char,char>, System.Numerics.IUnsignedNumber<char>
[System.Serializable]
public struct Char : IComparable, IConvertible
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct Char : IComparable, IComparable<char>, IConvertible, IEquatable<char>
public struct Char : IComparable, IComparable<char>, IEquatable<char>
type char = struct
    interface IConvertible
type char = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<char>
    interface ISpanFormattable
    interface ISpanParsable<char>
    interface IUtf8SpanFormattable
    interface IUtf8SpanParsable<char>
    interface IAdditionOperators<char, char, char>
    interface IAdditiveIdentity<char, char>
    interface IBinaryInteger<char>
    interface IBinaryNumber<char>
    interface IBitwiseOperators<char, char, char>
    interface IComparisonOperators<char, char, bool>
    interface IEqualityOperators<char, char, bool>
    interface IDecrementOperators<char>
    interface IDivisionOperators<char, char, char>
    interface IIncrementOperators<char>
    interface IModulusOperators<char, char, char>
    interface IMultiplicativeIdentity<char, char>
    interface IMultiplyOperators<char, char, char>
    interface INumber<char>
    interface INumberBase<char>
    interface ISubtractionOperators<char, char, char>
    interface IUnaryNegationOperators<char, char>
    interface IUnaryPlusOperators<char, char>
    interface IShiftOperators<char, int, char>
    interface IMinMaxValue<char>
    interface IUnsignedNumber<char>
type char = struct
    interface IConvertible
    interface ISpanFormattable
    interface IFormattable
type char = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<char>
    interface ISpanFormattable
    interface ISpanParsable<char>
    interface IAdditionOperators<char, char, char>
    interface IAdditiveIdentity<char, char>
    interface IBinaryInteger<char>
    interface IBinaryNumber<char>
    interface IBitwiseOperators<char, char, char>
    interface IComparisonOperators<char, char, bool>
    interface IEqualityOperators<char, char, bool>
    interface IDecrementOperators<char>
    interface IDivisionOperators<char, char, char>
    interface IIncrementOperators<char>
    interface IModulusOperators<char, char, char>
    interface IMultiplicativeIdentity<char, char>
    interface IMultiplyOperators<char, char, char>
    interface INumber<char>
    interface INumberBase<char>
    interface ISubtractionOperators<char, char, char>
    interface IUnaryNegationOperators<char, char>
    interface IUnaryPlusOperators<char, char>
    interface IShiftOperators<char, int, char>
    interface IMinMaxValue<char>
    interface IUnsignedNumber<char>
type char = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<char>
    interface ISpanFormattable
    interface ISpanParsable<char>
    interface IAdditionOperators<char, char, char>
    interface IAdditiveIdentity<char, char>
    interface IBinaryInteger<char>
    interface IBinaryNumber<char>
    interface IBitwiseOperators<char, char, char>
    interface IComparisonOperators<char, char, bool>
    interface IEqualityOperators<char, char, bool>
    interface IDecrementOperators<char>
    interface IDivisionOperators<char, char, char>
    interface IIncrementOperators<char>
    interface IModulusOperators<char, char, char>
    interface IMultiplicativeIdentity<char, char>
    interface IMultiplyOperators<char, char, char>
    interface INumber<char>
    interface INumberBase<char>
    interface ISubtractionOperators<char, char, char>
    interface IUnaryNegationOperators<char, char>
    interface IUnaryPlusOperators<char, char>
    interface IUtf8SpanFormattable
    interface IUtf8SpanParsable<char>
    interface IShiftOperators<char, int, char>
    interface IMinMaxValue<char>
    interface IUnsignedNumber<char>
[<System.Serializable>]
type char = struct
    interface IConvertible
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type char = struct
    interface IConvertible
type char = struct
Public Structure Char
Implements IComparable, IComparable(Of Char), IConvertible, IEquatable(Of Char)
Public Structure Char
Implements IAdditionOperators(Of Char, Char, Char), IAdditiveIdentity(Of Char, Char), IBinaryInteger(Of Char), IBinaryNumber(Of Char), IBitwiseOperators(Of Char, Char, Char), IComparable(Of Char), IComparisonOperators(Of Char, Char, Boolean), IConvertible, IDecrementOperators(Of Char), IDivisionOperators(Of Char, Char, Char), IEqualityOperators(Of Char, Char, Boolean), IEquatable(Of Char), IIncrementOperators(Of Char), IMinMaxValue(Of Char), IModulusOperators(Of Char, Char, Char), IMultiplicativeIdentity(Of Char, Char), IMultiplyOperators(Of Char, Char, Char), INumber(Of Char), INumberBase(Of Char), IParsable(Of Char), IShiftOperators(Of Char, Integer, Char), ISpanParsable(Of Char), ISubtractionOperators(Of Char, Char, Char), IUnaryNegationOperators(Of Char, Char), IUnaryPlusOperators(Of Char, Char), IUnsignedNumber(Of Char), IUtf8SpanParsable(Of Char)
Public Structure Char
Implements IComparable, IComparable(Of Char), IConvertible, IEquatable(Of Char), ISpanFormattable
Public Structure Char
Implements IAdditionOperators(Of Char, Char, Char), IAdditiveIdentity(Of Char, Char), IBinaryInteger(Of Char), IBinaryNumber(Of Char), IBitwiseOperators(Of Char, Char, Char), IComparable(Of Char), IComparisonOperators(Of Char, Char, Boolean), IConvertible, IDecrementOperators(Of Char), IDivisionOperators(Of Char, Char, Char), IEqualityOperators(Of Char, Char, Boolean), IEquatable(Of Char), IIncrementOperators(Of Char), IMinMaxValue(Of Char), IModulusOperators(Of Char, Char, Char), IMultiplicativeIdentity(Of Char, Char), IMultiplyOperators(Of Char, Char, Char), INumber(Of Char), INumberBase(Of Char), IParsable(Of Char), IShiftOperators(Of Char, Integer, Char), ISpanParsable(Of Char), ISubtractionOperators(Of Char, Char, Char), IUnaryNegationOperators(Of Char, Char), IUnaryPlusOperators(Of Char, Char), IUnsignedNumber(Of Char)
Public Structure Char
Implements IComparable, IConvertible
Public Structure Char
Implements IComparable, IComparable(Of Char), IEquatable(Of Char)
繼承
屬性
實作
IComparable IComparable<Char> IConvertible IEquatable<Char> IComparable<TSelf> IEquatable<TSelf> IFormattable IParsable<Char> IParsable<TSelf> ISpanFormattable ISpanParsable<Char> ISpanParsable<TSelf> IUtf8SpanFormattable IUtf8SpanParsable<Char> IUtf8SpanParsable<TSelf> IAdditionOperators<Char,Char,Char> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<Char,Char> IAdditiveIdentity<TSelf,TSelf> IBinaryInteger<Char> IBinaryNumber<Char> IBinaryNumber<TSelf> IBitwiseOperators<Char,Char,Char> IBitwiseOperators<TSelf,TSelf,TSelf> IComparisonOperators<Char,Char,Boolean> IComparisonOperators<TSelf,TSelf,Boolean> IDecrementOperators<Char> IDecrementOperators<TSelf> IDivisionOperators<Char,Char,Char> IDivisionOperators<TSelf,TSelf,TSelf> IEqualityOperators<Char,Char,Boolean> IEqualityOperators<TSelf,TOther,TResult> IEqualityOperators<TSelf,TSelf,Boolean> IIncrementOperators<Char> IIncrementOperators<TSelf> IMinMaxValue<Char> IModulusOperators<Char,Char,Char> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<Char,Char> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<Char,Char,Char> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<Char> INumber<TSelf> INumberBase<Char> INumberBase<TSelf> IShiftOperators<Char,Int32,Char> IShiftOperators<TSelf,Int32,TSelf> ISubtractionOperators<Char,Char,Char> ISubtractionOperators<TSelf,TSelf,TSelf> IUnaryNegationOperators<Char,Char> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<Char,Char> IUnaryPlusOperators<TSelf,TSelf> IUnsignedNumber<Char>

範例

以下程式碼範例展示了 中 Char的一些方法 。

using System;

public class CharStructureSample
{
    public static void Main()
    {
        char chA = 'A';
        char ch1 = '1';
        string str = "test string";

        Console.WriteLine(chA.CompareTo('B'));          //-----------  Output: "-1" (meaning 'A' is 1 less than 'B')
        Console.WriteLine(chA.Equals('A'));             //-----------  Output: "True"
        Console.WriteLine(Char.GetNumericValue(ch1));   //-----------  Output: "1"
        Console.WriteLine(Char.IsControl('\t'));        //-----------  Output: "True"
        Console.WriteLine(Char.IsDigit(ch1));           //-----------  Output: "True"
        Console.WriteLine(Char.IsLetter(','));          //-----------  Output: "False"
        Console.WriteLine(Char.IsLower('u'));           //-----------  Output: "True"
        Console.WriteLine(Char.IsNumber(ch1));          //-----------  Output: "True"
        Console.WriteLine(Char.IsPunctuation('.'));     //-----------  Output: "True"
        Console.WriteLine(Char.IsSeparator(str, 4));    //-----------  Output: "True"
        Console.WriteLine(Char.IsSymbol('+'));          //-----------  Output: "True"
        Console.WriteLine(Char.IsWhiteSpace(str, 4));   //-----------  Output: "True"
        Console.WriteLine(Char.Parse("S"));             //-----------  Output: "S"
        Console.WriteLine(Char.ToLower('M'));           //-----------  Output: "m"
        Console.WriteLine('x'.ToString());              //-----------  Output: "x"
    }
}
open System

let chA = 'A'
let ch1 = '1'
let str = "test string"

printfn $"{chA.CompareTo 'B'}"          //-----------  Output: "-1" (meaning 'A' is 1 less than 'B')
printfn $"{chA.Equals 'A'}"             //-----------  Output: "True"
printfn $"{Char.GetNumericValue ch1}"   //-----------  Output: "1"
printfn $"{Char.IsControl '\t'}"        //-----------  Output: "True"
printfn $"{Char.IsDigit ch1}"           //-----------  Output: "True"
printfn $"{Char.IsLetter ','}"          //-----------  Output: "False"
printfn $"{Char.IsLower 'u'}"           //-----------  Output: "True"
printfn $"{Char.IsNumber ch1}"          //-----------  Output: "True"
printfn $"{Char.IsPunctuation '.'}"     //-----------  Output: "True"
printfn $"{Char.IsSeparator(str, 4)}"   //-----------  Output: "True"
printfn $"{Char.IsSymbol '+'}"          //-----------  Output: "True"
printfn $"{Char.IsWhiteSpace(str, 4)}"  //-----------  Output: "True"
printfn $"""{Char.Parse "S"}"""         //-----------  Output: "S"
printfn $"{Char.ToLower 'M'}"           //-----------  Output: "m"
printfn $"{'x'}"                        //-----------  Output: "x"
Module CharStructure

    Public Sub Main()

        Dim chA As Char
        chA = "A"c
        Dim ch1 As Char
        ch1 = "1"c
        Dim str As String
        str = "test string"

        Console.WriteLine(chA.CompareTo("B"c))          ' Output: "-1" (meaning 'A' is 1 less than 'B')
        Console.WriteLine(chA.Equals("A"c))             ' Output: "True"
        Console.WriteLine(Char.GetNumericValue(ch1))    ' Output: "1"
        Console.WriteLine(Char.IsControl(Chr(9)))       ' Output: "True"
        Console.WriteLine(Char.IsDigit(ch1))            ' Output: "True"
        Console.WriteLine(Char.IsLetter(","c))          ' Output: "False"
        Console.WriteLine(Char.IsLower("u"c))           ' Output: "True"
        Console.WriteLine(Char.IsNumber(ch1))           ' Output: "True"
        Console.WriteLine(Char.IsPunctuation("."c))     ' Output: "True"
        Console.WriteLine(Char.IsSeparator(str, 4))     ' Output: "True"
        Console.WriteLine(Char.IsSymbol("+"c))          ' Output: "True"
        Console.WriteLine(Char.IsWhiteSpace(str, 4))    ' Output: "True"
        Console.WriteLine(Char.Parse("S"))              ' Output: "S"
        Console.WriteLine(Char.ToLower("M"c))           ' Output: "m"
        Console.WriteLine("x"c.ToString())              ' Output: "x"

    End Sub

End Module

備註

結構 Char 代表使用UTF-16編碼的Unicode字碼點。 物件的值 Char 是其16位數值 (序數) 值。

如果您不熟悉 Unicode、純量值、字碼點、代理字組、UTF-16 和 Rune 類型,請參閱 .NET 中的字元編碼簡介

本文會檢查 物件與字元之間的 Char 關聯性,並討論使用 Char 實例執行的一些常見工作。 我們建議您考慮引進於 .NET Core 3.0 的 Rune 類型,作為 Char 的替代方案來執行其中一些工作。

Char 物件、Unicode 字元和字串

String物件是一個由Char結構組成的循序集合,表示一個文字字串。 大部分 Unicode 字元都可以由單 Char 一物件表示,但編碼為基底字元、代理字組和/或組合字元序列的字元是由多個 Char 物件表示。 因此, Char 物件中的 String 結構不一定等於單一 Unicode 字元。

在下列情況下,會使用多個16位程式代碼單位來代表單一 Unicode 字元:

  • 字元,其可能包含單一字元或基底字元,後面接著一或多個結合字元。 例如,字元 ä 是由 Char 程式代碼單位為 U+0061 的物件表示,後面接著程式 Char 代碼單位為 U+0308 的物件。 (字元 ä 也可以由具有 U+00E4 程式代碼單位的單 Char 一物件定義。下列範例說明字元 ä 是由兩個 Char 對象所組成。

    using System;
    using System.IO;
    
    public class Example1
    {
        public static void Main()
        {
            StreamWriter sw = new StreamWriter("chars1.txt");
            char[] chars = [ '\u0061', '\u0308' ];
            string strng = new String(chars);
            sw.WriteLine(strng);
            sw.Close();
        }
    }
    // The example produces the following output:
    //       ä
    
    open System
    open System.IO
    
    let sw = new StreamWriter("chars1.txt")
    let chars = [| '\u0061'; '\u0308' |]
    let string = String chars
    sw.WriteLine string
    sw.Close()
    
    // The example produces the following output:
    //       ä
    
    Imports System.IO
    
    Module Example2
        Public Sub Main()
            Dim sw As New StreamWriter("chars1.txt")
            Dim chars() As Char = {ChrW(&H61), ChrW(&H308)}
            Dim strng As New String(chars)
            sw.WriteLine(strng)
            sw.Close()
        End Sub
    End Module
    ' The example produces the following output:
    '       ä
    
  • Unicode 基本多語平面以外的字元(BMP)。 除了代表平面 0 的 BMP 之外,Unicode 還支援 16 個平面。 Unicode 字碼點以 UTF-32 表示,其為包含平面的 21 位值。 例如,U+1D160 代表音樂符號八分音符字元。 由於UTF-16編碼只有16位,因此 BMP以外的字元會以UTF-16中的代理字組來表示。 下列範例說明,音樂符號「八分音符」的字符 U+1D160 在 UTF-32 中的等價值是 U+D834 U+DD60。 U+D834 是高代理;高代理範圍從U+D800到U+DBFF。 U+DD60 是低代理;低代理範圍從U+DC00到U+DFFF。

    using System;
    using System.IO;
    
    public class Example3
    {
        public static void Main()
        {
            StreamWriter sw = new StreamWriter(@".\chars2.txt");
            int utf32 = 0x1D160;
            string surrogate = Char.ConvertFromUtf32(utf32);
            sw.WriteLine($"U+{utf32:X6} UTF-32 = {surrogate} ({ShowCodePoints(surrogate)}) UTF-16");
            sw.Close();
        }
    
        private static string ShowCodePoints(string value)
        {
            string retval = null;
            foreach (var ch in value)
                retval += $"U+{Convert.ToUInt16(ch):X4} ";
    
            return retval.Trim();
        }
    }
    // The example produces the following output:
    //       U+01D160 UTF-32 = ð (U+D834 U+DD60) UTF-16
    
    open System
    open System.IO
    
    let showCodePoints (value: char seq) =
        let str =
            value
            |> Seq.map (fun ch -> $"U+{Convert.ToUInt16 ch:X4}")
            |> String.concat ""
        str.Trim()
    
    let sw = new StreamWriter(@".\chars2.txt")
    let utf32 = 0x1D160
    let surrogate = Char.ConvertFromUtf32 utf32
    sw.WriteLine $"U+{utf32:X6} UTF-32 = {surrogate} ({showCodePoints surrogate}) UTF-16"
    sw.Close()
    
    // The example produces the following output:
    //       U+01D160 UTF-32 = ð (U+D834 U+DD60) UTF-16
    
    Imports System.IO
    
    Module Example4
        Public Sub Main()
            Dim sw As New StreamWriter(".\chars2.txt")
            Dim utf32 As Integer = &H1D160
            Dim surrogate As String = Char.ConvertFromUtf32(utf32)
            sw.WriteLine("U+{0:X6} UTF-32 = {1} ({2}) UTF-16",
                       utf32, surrogate, ShowCodePoints(surrogate))
            sw.Close()
        End Sub
    
        Private Function ShowCodePoints(value As String) As String
            Dim retval As String = Nothing
            For Each ch In value
                retval += String.Format("U+{0:X4} ", Convert.ToUInt16(ch))
            Next
            Return retval.Trim()
        End Function
    End Module
    ' The example produces the following output:
    '       U+01D160 UTF-32 = ð (U+D834 U+DD60) UTF-16
    

字元和字元類別

每個 Unicode 字元或有效的代理字組都屬於 Unicode 類別。 在 .NET 中,Unicode 類別以UnicodeCategory列舉成員表示,例如包含UnicodeCategory.CurrencySymbolUnicodeCategory.LowercaseLetterUnicodeCategory.SpaceSeparator等值。

若要判斷字元的 Unicode 類別,請呼叫 GetUnicodeCategory 方法。 例如,下列範例會呼叫 GetUnicodeCategory 來顯示字串中每個字元的 Unicode 類別。 只有在 實例中 String 沒有代理字組時,此範例才能正確運作。

using System;
using System.Globalization;

class Example
{
   public static void Main()
   {
      // Define a string with a variety of character categories.
      String s = "The red car drove down the long, narrow, secluded road.";
      // Determine the category of each character.
      foreach (var ch in s)
         Console.WriteLine($"'{ch}': {Char.GetUnicodeCategory(ch)}");
   }
}
// The example displays the following output:
//      'T': UppercaseLetter
//      'h': LowercaseLetter
//      'e': LowercaseLetter
//      ' ': SpaceSeparator
//      'r': LowercaseLetter
//      'e': LowercaseLetter
//      'd': LowercaseLetter
//      ' ': SpaceSeparator
//      'c': LowercaseLetter
//      'a': LowercaseLetter
//      'r': LowercaseLetter
//      ' ': SpaceSeparator
//      'd': LowercaseLetter
//      'r': LowercaseLetter
//      'o': LowercaseLetter
//      'v': LowercaseLetter
//      'e': LowercaseLetter
//      ' ': SpaceSeparator
//      'd': LowercaseLetter
//      'o': LowercaseLetter
//      'w': LowercaseLetter
//      'n': LowercaseLetter
//      ' ': SpaceSeparator
//      't': LowercaseLetter
//      'h': LowercaseLetter
//      'e': LowercaseLetter
//      ' ': SpaceSeparator
//      'l': LowercaseLetter
//      'o': LowercaseLetter
//      'n': LowercaseLetter
//      'g': LowercaseLetter
//      ',': OtherPunctuation
//      ' ': SpaceSeparator
//      'n': LowercaseLetter
//      'a': LowercaseLetter
//      'r': LowercaseLetter
//      'r': LowercaseLetter
//      'o': LowercaseLetter
//      'w': LowercaseLetter
//      ',': OtherPunctuation
//      ' ': SpaceSeparator
//      's': LowercaseLetter
//      'e': LowercaseLetter
//      'c': LowercaseLetter
//      'l': LowercaseLetter
//      'u': LowercaseLetter
//      'd': LowercaseLetter
//      'e': LowercaseLetter
//      'd': LowercaseLetter
//      ' ': SpaceSeparator
//      'r': LowercaseLetter
//      'o': LowercaseLetter
//      'a': LowercaseLetter
//      'd': LowercaseLetter
//      '.': OtherPunctuation
open System

// Define a string with a variety of character categories.
let s = "The red car drove down the long, narrow, secluded road."
// Determine the category of each character.
for ch in s do
    printfn $"'{ch}': {Char.GetUnicodeCategory ch}"

// The example displays the following output:
//      'T': UppercaseLetter
//      'h': LowercaseLetter
//      'e': LowercaseLetter
//      ' ': SpaceSeparator
//      'r': LowercaseLetter
//      'e': LowercaseLetter
//      'd': LowercaseLetter
//      ' ': SpaceSeparator
//      'c': LowercaseLetter
//      'a': LowercaseLetter
//      'r': LowercaseLetter
//      ' ': SpaceSeparator
//      'd': LowercaseLetter
//      'r': LowercaseLetter
//      'o': LowercaseLetter
//      'v': LowercaseLetter
//      'e': LowercaseLetter
//      ' ': SpaceSeparator
//      'd': LowercaseLetter
//      'o': LowercaseLetter
//      'w': LowercaseLetter
//      'n': LowercaseLetter
//      ' ': SpaceSeparator
//      't': LowercaseLetter
//      'h': LowercaseLetter
//      'e': LowercaseLetter
//      ' ': SpaceSeparator
//      'l': LowercaseLetter
//      'o': LowercaseLetter
//      'n': LowercaseLetter
//      'g': LowercaseLetter
//      ',': OtherPunctuation
//      ' ': SpaceSeparator
//      'n': LowercaseLetter
//      'a': LowercaseLetter
//      'r': LowercaseLetter
//      'r': LowercaseLetter
//      'o': LowercaseLetter
//      'w': LowercaseLetter
//      ',': OtherPunctuation
//      ' ': SpaceSeparator
//      's': LowercaseLetter
//      'e': LowercaseLetter
//      'c': LowercaseLetter
//      'l': LowercaseLetter
//      'u': LowercaseLetter
//      'd': LowercaseLetter
//      'e': LowercaseLetter
//      'd': LowercaseLetter
//      ' ': SpaceSeparator
//      'r': LowercaseLetter
//      'o': LowercaseLetter
//      'a': LowercaseLetter
//      'd': LowercaseLetter
//      '.': OtherPunctuation
Imports System.Globalization

Module Example1
    Public Sub Main()
        ' Define a string with a variety of character categories.
        Dim s As String = "The car drove down the narrow, secluded road."
        ' Determine the category of each character.
        For Each ch In s
            Console.WriteLine("'{0}': {1}", ch, Char.GetUnicodeCategory(ch))
        Next
    End Sub
End Module
' The example displays the following output:
'       'T': UppercaseLetter
'       'h': LowercaseLetter
'       'e': LowercaseLetter
'       ' ': SpaceSeparator
'       'r': LowercaseLetter
'       'e': LowercaseLetter
'       'd': LowercaseLetter
'       ' ': SpaceSeparator
'       'c': LowercaseLetter
'       'a': LowercaseLetter
'       'r': LowercaseLetter
'       ' ': SpaceSeparator
'       'd': LowercaseLetter
'       'r': LowercaseLetter
'       'o': LowercaseLetter
'       'v': LowercaseLetter
'       'e': LowercaseLetter
'       ' ': SpaceSeparator
'       'd': LowercaseLetter
'       'o': LowercaseLetter
'       'w': LowercaseLetter
'       'n': LowercaseLetter
'       ' ': SpaceSeparator
'       't': LowercaseLetter
'       'h': LowercaseLetter
'       'e': LowercaseLetter
'       ' ': SpaceSeparator
'       'l': LowercaseLetter
'       'o': LowercaseLetter
'       'n': LowercaseLetter
'       'g': LowercaseLetter
'       ',': OtherPunctuation
'       ' ': SpaceSeparator
'       'n': LowercaseLetter
'       'a': LowercaseLetter
'       'r': LowercaseLetter
'       'r': LowercaseLetter
'       'o': LowercaseLetter
'       'w': LowercaseLetter
'       ',': OtherPunctuation
'       ' ': SpaceSeparator
'       's': LowercaseLetter
'       'e': LowercaseLetter
'       'c': LowercaseLetter
'       'l': LowercaseLetter
'       'u': LowercaseLetter
'       'd': LowercaseLetter
'       'e': LowercaseLetter
'       'd': LowercaseLetter
'       ' ': SpaceSeparator
'       'r': LowercaseLetter
'       'o': LowercaseLetter
'       'a': LowercaseLetter
'       'd': LowercaseLetter
'       '.': OtherPunctuation

就內部而言,對於超出 ASCII 範圍(U+0000 到 U+007F)的字元,GetUnicodeCategory 方法取決於 CharUnicodeInfo 類別報告的 Unicode 類別。 Unicode 字元依據 Unicode 標準 8.0.0 版本進行分類。

字元和文字元素

因為單一字元可以由多個 Char 物件表示,所以使用個別 Char 物件並不一定有意義。 例如,下列範例會將代表愛琴海數位零到 9 的 Unicode 字碼點轉換為 UTF-16 編碼的程式代碼單位。 因為它錯誤地將物件與字元相等 Char ,所以錯誤地報告產生的字串有 20 個字元。

using System;

public class Example5
{
    public static void Main()
    {
        string result = String.Empty;
        for (int ctr = 0x10107; ctr <= 0x10110; ctr++)  // Range of Aegean numbers.
            result += Char.ConvertFromUtf32(ctr);

        Console.WriteLine($"The string contains {result.Length} characters.");
    }
}
// The example displays the following output:
//     The string contains 20 characters.
open System

let result =
    [ for i in 0x10107..0x10110 do  // Range of Aegean numbers.
        Char.ConvertFromUtf32 i ]
    |> String.concat ""

printfn $"The string contains {result.Length} characters."


// The example displays the following output:
//     The string contains 20 characters.
Module Example5
    Public Sub Main()
        Dim result As String = String.Empty
        For ctr As Integer = &H10107 To &H10110     ' Range of Aegean numbers.
            result += Char.ConvertFromUtf32(ctr)
        Next
        Console.WriteLine("The string contains {0} characters.", result.Length)
    End Sub
End Module
' The example displays the following output:
'     The string contains 20 characters.

您可以執行下列動作,以避免 Char 假設物件代表單一字元:

  • 您可以完全使用 String 物件,而不是使用其個別字元來表示和分析語言內容。

  • 您可以使用 String.EnumerateRunes ,如下列範例所示:

    int CountLetters(string s)
    {
        int letterCount = 0;
    
        foreach (Rune rune in s.EnumerateRunes())
        {
            if (Rune.IsLetter(rune))
            { letterCount++; }
        }
    
        return letterCount;
    }
    
    let countLetters (s: string) =
        let mutable letterCount = 0
    
        for rune in s.EnumerateRunes() do
            if Rune.IsLetter rune then
                letterCount <- letterCount + 1
    
        letterCount
    
  • 您可以使用 類別 StringInfo 來處理文字專案,而不是個別 Char 物件。 下列範例會使用StringInfo物件來計算包含從愛琴海數字零到九的字串中的文字元素數量。 因為它會將代理對視為單一字元,所以它會正確地報告字串包含十個字元。

    using System;
    using System.Globalization;
    
    public class Example4
    {
        public static void Main()
        {
            string result = String.Empty;
            for (int ctr = 0x10107; ctr <= 0x10110; ctr++)  // Range of Aegean numbers.
                result += Char.ConvertFromUtf32(ctr);
    
            StringInfo si = new StringInfo(result);
            Console.WriteLine($"The string contains {si.LengthInTextElements} characters.");
        }
    }
    // The example displays the following output:
    //       The string contains 10 characters.
    
    open System
    open System.Globalization
    
    let result =
        [ for i in 0x10107..0x10110 do  // Range of Aegean numbers.
            Char.ConvertFromUtf32 i ]
        |> String.concat ""
    
    
    let si = StringInfo result
    printfn $"The string contains {si.LengthInTextElements} characters."
    
    // The example displays the following output:
    //       The string contains 10 characters.
    
    Imports System.Globalization
    
    Module Example6
        Public Sub Main()
            Dim result As String = String.Empty
            For ctr As Integer = &H10107 To &H10110     ' Range of Aegean numbers.
                result += Char.ConvertFromUtf32(ctr)
            Next
            Dim si As New StringInfo(result)
            Console.WriteLine("The string contains {0} characters.", si.LengthInTextElements)
        End Sub
    End Module
    ' The example displays the following output:
    '       The string contains 10 characters.
    
  • 如果字串包含一或多個組合字元的基底字元,您可以呼叫 String.Normalize 方法,將子字串轉換成單一 UTF-16 編碼的程式代碼單位。 下列範例會呼叫 String.Normalize 方法,將基底字元 U+0061 (LATIN SMALL LETTER A) 和組合字元 U+0308 (COMBINING DIAERESIS) 轉換成 U+00E4 (LATIN SMALL LETTER A WITH DIAERESIS)。

    using System;
    
    public class Example2
    {
        public static void Main()
        {
            string combining = "\u0061\u0308";
            ShowString(combining);
    
            string normalized = combining.Normalize();
            ShowString(normalized);
        }
    
        private static void ShowString(string s)
        {
            Console.Write($"Length of string: {s.Length} (");
            for (int ctr = 0; ctr < s.Length; ctr++)
            {
                Console.Write($"U+{Convert.ToUInt16(s[ctr]):X4}");
                if (ctr != s.Length - 1) Console.Write(" ");
            }
            Console.WriteLine(")\n");
        }
    }
    // The example displays the following output:
    //       Length of string: 2 (U+0061 U+0308)
    //
    //       Length of string: 1 (U+00E4)
    
    open System
    
    let showString (s: string) =
        printf $"Length of string: {s.Length} ("
        for i = 0 to s.Length - 1 do
            printf $"U+{Convert.ToUInt16 s[i]:X4}"
            if i <> s.Length - 1 then printf " "
        printfn ")\n"
    
    let combining = "\u0061\u0308"
    showString combining
    
    let normalized = combining.Normalize()
    showString normalized
    
    // The example displays the following output:
    //       Length of string: 2 (U+0061 U+0308)
    //
    //       Length of string: 1 (U+00E4)
    
    Module Example3
        Public Sub Main()
            Dim combining As String = ChrW(&H61) + ChrW(&H308)
            ShowString(combining)
    
            Dim normalized As String = combining.Normalize()
            ShowString(normalized)
        End Sub
    
        Private Sub ShowString(s As String)
            Console.Write("Length of string: {0} (", s.Length)
            For ctr As Integer = 0 To s.Length - 1
                Console.Write("U+{0:X4}", Convert.ToUInt16(s(ctr)))
                If ctr <> s.Length - 1 Then Console.Write(" ")
            Next
            Console.WriteLine(")")
            Console.WriteLine()
        End Sub
    End Module
    ' The example displays the following output:
    '       Length of string: 2 (U+0061 U+0308)
    '       
    '       Length of string: 1 (U+00E4)
    

一般作業

結構Char提供的方法包括:比較Char物件、將目前Char物件的值轉換為另一種型別的Char物件,以及判斷Char物件的 Unicode 類別。

若要執行此操作 System.Char使用這些方法
比較 Char 物件 CompareToEquals
將程式代碼點轉換成字串 ConvertFromUtf32

另請參閱Rune類型。
Char 物件或代理對 Char 物件轉換成碼位 針對單一字元: Convert.ToInt32(Char)

針對字串中的代理字組或字元: Char.ConvertToUtf32

另請參閱Rune類型。
取得字元的 Unicode 類別 GetUnicodeCategory

請參閱 Rune.GetUnicodeCategory
判斷字元是否在特定 Unicode 類別中,例如數位、字母、標點符號、控制字元等等 IsControlIsDigitIsHighSurrogateIsLetterIsLetterOrDigitIsLowerIsLowSurrogateIsNumberIsPunctuationIsSeparatorIsSurrogateIsSurrogatePairIsSymbolIsUpperIsWhiteSpace

另請參閱類型的 Rune 對應方法。
Char將代表數位的物件轉換為數值類型 GetNumericValue

請參閱 Rune.GetNumericValue
將字串中的字元轉換成 Char 物件 ParseTryParse
Char 物件轉換成 String 物件 ToString
更改Char物件的字母大小寫 ToLowerToLowerInvariantToUpperToUpperInvariant

另請參閱類型的 Rune 對應方法。

Char 值與Interop

當 Managed Char 類型表示為 Unicode UTF-16 編碼程式代碼單位時,Interop 封送器預設會將字元集轉換成 ANSI。 您可以將 DllImportAttribute 屬性套用至平台調用宣告中,並將 StructLayoutAttribute 屬性套用至 COM 互操作宣告,以控制封送的 Char 類型所使用的字元集。

欄位

名稱 Description
MaxValue

代表 的最大可能值 Char。 此欄位是常數。

MinValue

代表 的最小值 Char。 此欄位是常數。

方法

名稱 Description
CompareTo(Char)

將此實例與指定 Char 物件比較,並指示該實例是否在排序順序中與指定 Char 物件相鄰、之後或出現的位置相同。

CompareTo(Object)

將此實例與指定物件比較,並指示該實例是否在排序順序中與指定 Object物件之前、之後或出現於相同位置。

ConvertFromUtf32(Int32)

將指定的 Unicode 字碼點轉換成 UTF-16 編碼字串。

ConvertToUtf32(Char, Char)

將UTF-16編碼代理組的值轉換成 Unicode 字碼點。

ConvertToUtf32(String, Int32)

將位於字串中指定位置的UTF-16編碼字元或 Surrogate 字組值轉換成 Unicode 字碼點。

Equals(Char, StringComparison)

以UTF-16程式代碼單位表示字元。

Equals(Char)

回傳一個值,表示該實例是否等於指定 Char 物件。

Equals(Object)

傳回值,這個值表示這個實例是否等於指定的物件。

GetHashCode()

傳回這個實例的哈希碼。

GetNumericValue(Char)

將指定的數值 Unicode 字元轉換為雙精確度浮點數。

GetNumericValue(String, Int32)

將指定字串中指定位置的數值 Unicode 字元轉換為雙精確度浮點數。

GetTypeCode()

回傳 TypeCode 的值型別 Char

GetUnicodeCategory(Char)

將指定的 Unicode 字元分類為由其中一個 UnicodeCategory 值識別的群組。

GetUnicodeCategory(String, Int32)

將字串中指定位置的字元分類為由 UnicodeCategory 其中一個值識別的群組。

IsAscii(Char)

true為 ASCII 字元([ U+0000..U+007F ]) 則回傳c

IsAsciiDigit(Char)

指出字元是否分類為 ASCII 數位。

IsAsciiHexDigit(Char)

表示字元是否被分類為 ASCII 十六進位數字。

IsAsciiHexDigitLower(Char)

表示字元是否被分類為 ASCII 小寫十六進位數字。

IsAsciiHexDigitUpper(Char)

表示字元是否被分類為 ASCII 大寫十六進位數字。

IsAsciiLetter(Char)

指出字元是否分類為 ASCII 字母。

IsAsciiLetterLower(Char)

指出字元是否分類為小寫 ASCII 字母。

IsAsciiLetterOrDigit(Char)

指出字元是否分類為 ASCII 字母或數位。

IsAsciiLetterUpper(Char)

指出字元是否分類為大寫 ASCII 字母。

IsBetween(Char, Char, Char)

指出字元是否在指定的內含範圍內。

IsControl(Char)

指出指定的 Unicode 字元是否分類為控制字元。

IsControl(String, Int32)

指出指定字串中指定位置的字元是否分類為控制字元。

IsDigit(Char)

指出指定的 Unicode 字元是否分類為十進位數。

IsDigit(String, Int32)

指出指定字串中指定位置的字元是否分類為十進位數。

IsHighSurrogate(Char)

表示指定 Char 物體是否為高替代物體。

IsHighSurrogate(String, Int32)

表示字串中指定位置的物件是否 Char 為高替代物件。

IsLetter(Char)

指出指定的 Unicode 字元是否分類為 Unicode 字母。

IsLetter(String, Int32)

指出指定字串中指定位置的字元是否分類為 Unicode 字母。

IsLetterOrDigit(Char)

指出指定的 Unicode 字元是否分類為字母或十進位數。

IsLetterOrDigit(String, Int32)

指出指定字串中指定位置的字元是否分類為字母或十進位數。

IsLower(Char)

指出指定的 Unicode 字元是否分類為小寫字母。

IsLower(String, Int32)

指出指定字串中指定位置的字元是否分類為小寫字母。

IsLowSurrogate(Char)

表示指定 Char 物體是否為低代體。

IsLowSurrogate(String, Int32)

表示字串中指定位置的物件是否 Char 為低代替。

IsNumber(Char)

指出指定的 Unicode 字元是否分類為數位。

IsNumber(String, Int32)

指出指定字串中指定位置的字元是否分類為數位。

IsPunctuation(Char)

指出指定的 Unicode 字元是否分類為標點符號。

IsPunctuation(String, Int32)

指出指定字串中指定位置的字元是否分類為標點符號。

IsSeparator(Char)

指出指定的 Unicode 字元是否分類為分隔符。

IsSeparator(String, Int32)

指出指定字串中指定位置的字元是否分類為分隔符。

IsSurrogate(Char)

表示指定字元是否有替代代碼單元。

IsSurrogate(String, Int32)

表示指定字串中指定位置的字元是否擁有替代碼單元。

IsSurrogatePair(Char, Char)

表示兩個指定 Char 物件是否構成替代對。

IsSurrogatePair(String, Int32)

表示在字串中指定位置相 Char 鄰的兩個物體是否構成替代對。

IsSymbol(Char)

指出指定的 Unicode 字元是否分類為符號字元。

IsSymbol(String, Int32)

指出指定字串中指定位置的字元是否分類為符號字元。

IsUpper(Char)

指出指定的 Unicode 字元是否分類為大寫字母。

IsUpper(String, Int32)

指出指定字串中指定位置的字元是否分類為大寫字母。

IsWhiteSpace(Char)

指出指定的 Unicode 字元是否分類為空格符。

IsWhiteSpace(String, Int32)

指出指定字串中指定位置的字元是否分類為空格符。

Parse(String)

將指定字串的值轉換為其相等的 Unicode 字元。

ToLower(Char, CultureInfo)

使用指定的特定文化特性格式資訊,將指定 Unicode 字元的值轉換為其小寫對等專案。

ToLower(Char)

將 Unicode 字元的值轉換為其小寫對等專案。

ToLowerInvariant(Char)

使用不因文化特性的大小寫規則,將 Unicode 字元的值轉換為其小寫對等專案。

ToString()

將這個實例的值轉換為其相等的字串表示。

ToString(Char)

將指定的 Unicode 字元轉換為其相等的字串表示。

ToString(IFormatProvider)

使用指定的特定文化特性格式資訊,將這個實例的值轉換為其相等的字串表示。

ToUpper(Char, CultureInfo)

使用指定的特定文化特性格式資訊,將指定 Unicode 字元的值轉換為其大寫對等專案。

ToUpper(Char)

將 Unicode 字元的值轉換為其大寫對等專案。

ToUpperInvariant(Char)

使用不因文化特性的大小寫規則,將 Unicode 字元的值轉換為其大寫對等專案。

TryParse(String, Char)

將指定字串的值轉換為其相等的 Unicode 字元。 傳回碼表示轉換成功或失敗。

明確介面實作

名稱 Description
IAdditionOperators<Char,Char,Char>.Addition(Char, Char)

將兩個值加在一起以計算其總和。

IAdditionOperators<Char,Char,Char>.CheckedAddition(Char, Char)

將兩個值加在一起以計算其總和。

IAdditiveIdentity<Char,Char>.AdditiveIdentity

取得目前型別的加法識別。

IBinaryInteger<Char>.GetByteCount()

取得將被寫入為 TryWriteLittleEndian(Span<Byte>, Int32)的一部分的位元組數。

IBinaryInteger<Char>.GetShortestBitLength()

取得最短兩個目前值的補碼表示長度,以位為單位。

IBinaryInteger<Char>.LeadingZeroCount(Char)

計算值中前置零位的數目。

IBinaryInteger<Char>.Log10(Char)

以UTF-16程式代碼單位表示字元。

IBinaryInteger<Char>.PopCount(Char)

計算值中所設定的位數。

IBinaryInteger<Char>.RotateLeft(Char, Int32)

以指定的數量旋轉值。

IBinaryInteger<Char>.RotateRight(Char, Int32)

以指定的數量向右旋轉值。

IBinaryInteger<Char>.TrailingZeroCount(Char)

計算值中尾端零位的數目。

IBinaryInteger<Char>.TryReadBigEndian(ReadOnlySpan<Byte>, Boolean, Char)

以UTF-16程式代碼單位表示字元。

IBinaryInteger<Char>.TryReadLittleEndian(ReadOnlySpan<Byte>, Boolean, Char)

以UTF-16程式代碼單位表示字元。

IBinaryInteger<Char>.TryWriteBigEndian(Span<Byte>, Int32)

嘗試以 big-endian 格式將目前的值寫入指定的範圍。

IBinaryInteger<Char>.TryWriteLittleEndian(Span<Byte>, Int32)

嘗試將目前值以小到尾格式寫入指定的範圍。

IBinaryNumber<Char>.AllBitsSet

取得已設定所有位之二進位型別的實例。

IBinaryNumber<Char>.IsPow2(Char)

判斷值是否為兩個乘冪。

IBinaryNumber<Char>.Log2(Char)

計算 值的log2。

IBitwiseOperators<Char,Char,Char>.BitwiseAnd(Char, Char)

計算兩個值的位和 。

IBitwiseOperators<Char,Char,Char>.BitwiseOr(Char, Char)

計算兩個值的位或兩個值。

IBitwiseOperators<Char,Char,Char>.ExclusiveOr(Char, Char)

計算兩個值的獨佔或兩個值。

IBitwiseOperators<Char,Char,Char>.OnesComplement(Char)

計算指定值的 ones-complement 表示法。

IComparable.CompareTo(Object)

比較目前實例與相同型別的另一個物件,並傳回整數,指出目前的實例是否在排序順序中與其他對象位於相同位置。

IComparisonOperators<Char,Char,Boolean>.GreaterThan(Char, Char)

比較兩個值,以判斷哪一個值更大。

IComparisonOperators<Char,Char,Boolean>.GreaterThanOrEqual(Char, Char)

比較兩個值,以判斷哪一個值大於或相等。

IComparisonOperators<Char,Char,Boolean>.LessThan(Char, Char)

比較兩個值,以判斷哪一個值較少。

IComparisonOperators<Char,Char,Boolean>.LessThanOrEqual(Char, Char)

比較兩個值,以判斷哪一個值小於或相等。

IConvertible.GetTypeCode()

這次回傳 。TypeCode

IConvertible.ToBoolean(IFormatProvider)

此轉換不被支援。 嘗試這樣做會產生 InvalidCastException

IConvertible.ToByte(IFormatProvider)

關於此成員的描述,請參見 ToByte(IFormatProvider)

IConvertible.ToChar(IFormatProvider)

關於此成員的描述,請參見 ToChar(IFormatProvider)

IConvertible.ToDateTime(IFormatProvider)

此轉換不被支援。 嘗試這樣做會產生 InvalidCastException

IConvertible.ToDecimal(IFormatProvider)

此轉換不被支援。 嘗試這樣做會產生 InvalidCastException

IConvertible.ToDouble(IFormatProvider)

此轉換不被支援。 嘗試這樣做會產生 InvalidCastException

IConvertible.ToInt16(IFormatProvider)

關於此成員的描述,請參見 ToInt16(IFormatProvider)

IConvertible.ToInt32(IFormatProvider)

關於此成員的描述,請參見 ToInt32(IFormatProvider)

IConvertible.ToInt64(IFormatProvider)

關於此成員的描述,請參見 ToInt64(IFormatProvider)

IConvertible.ToSByte(IFormatProvider)

關於此成員的描述,請參見 ToSByte(IFormatProvider)

IConvertible.ToSingle(IFormatProvider)

此轉換不被支援。 嘗試這樣做會產生 InvalidCastException

IConvertible.ToString(IFormatProvider)

使用指定的特定文化特性格式資訊,將這個實例的值轉換為相等的字串。

IConvertible.ToType(Type, IFormatProvider)

關於此成員的描述,請參見 ToType(Type, IFormatProvider)

IConvertible.ToUInt16(IFormatProvider)

關於此成員的描述,請參見 ToUInt16(IFormatProvider)

IConvertible.ToUInt32(IFormatProvider)

關於此成員的描述,請參見 ToUInt32(IFormatProvider)

IConvertible.ToUInt64(IFormatProvider)

關於此成員的描述,請參見 ToUInt64(IFormatProvider)

IDecrementOperators<Char>.CheckedDecrement(Char)

遞減值。

IDecrementOperators<Char>.Decrement(Char)

遞減值。

IDivisionOperators<Char,Char,Char>.Division(Char, Char)

將一個值除以計算其商數。

IEqualityOperators<Char,Char,Boolean>.Equality(Char, Char)

比較兩個值以判斷相等。

IEqualityOperators<Char,Char,Boolean>.Inequality(Char, Char)

比較兩個值以判斷不相等。

IFormattable.ToString(String, IFormatProvider)

使用指定的格式,格式化目前實例的值。

IIncrementOperators<Char>.CheckedIncrement(Char)

遞增值。

IIncrementOperators<Char>.Increment(Char)

遞增值。

IMinMaxValue<Char>.MaxValue

取得目前型別的最大值。

IMinMaxValue<Char>.MinValue

取得目前型別的最小值。

IModulusOperators<Char,Char,Char>.Modulus(Char, Char)

將兩個值分割在一起,以計算其模數或餘數。

IMultiplicativeIdentity<Char,Char>.MultiplicativeIdentity

取得目前型別的乘法識別。

IMultiplyOperators<Char,Char,Char>.CheckedMultiply(Char, Char)

將兩個值相乘以計算其產品。

IMultiplyOperators<Char,Char,Char>.Multiply(Char, Char)

將兩個值相乘以計算其產品。

INumberBase<Char>.Abs(Char)

計算值的絕對值。

INumberBase<Char>.IsCanonical(Char)

判斷值是否在其標準表示法中。

INumberBase<Char>.IsComplexNumber(Char)

判斷值是否代表複數。

INumberBase<Char>.IsEvenInteger(Char)

判斷值是否代表偶數整數。

INumberBase<Char>.IsFinite(Char)

判斷值是否有限。

INumberBase<Char>.IsImaginaryNumber(Char)

判斷值是否代表純虛數。

INumberBase<Char>.IsInfinity(Char)

判斷值是否為無限。

INumberBase<Char>.IsInteger(Char)

判斷值是否代表整數。

INumberBase<Char>.IsNaN(Char)

判斷值是否為 NaN。

INumberBase<Char>.IsNegative(Char)

判斷值是否為負值。

INumberBase<Char>.IsNegativeInfinity(Char)

判斷值是否為負無限大。

INumberBase<Char>.IsNormal(Char)

判斷值是否正常。

INumberBase<Char>.IsOddInteger(Char)

判斷值是否代表奇數整數。

INumberBase<Char>.IsPositive(Char)

判斷值是否為正數。

INumberBase<Char>.IsPositiveInfinity(Char)

判斷值是否為正無限大。

INumberBase<Char>.IsRealNumber(Char)

判斷值是否代表實數。

INumberBase<Char>.IsSubnormal(Char)

判斷值是否為次正規。

INumberBase<Char>.IsZero(Char)

判斷值是否為零。

INumberBase<Char>.MaxMagnitude(Char, Char)

比較兩個值與計算,這兩個值更大。

INumberBase<Char>.MaxMagnitudeNumber(Char, Char)

比較兩個值以計算出哪個大小較大,若輸入為 NaN則返回另一個值。

INumberBase<Char>.MinMagnitude(Char, Char)

比較兩個值與計算比較較少。

INumberBase<Char>.MinMagnitudeNumber(Char, Char)

比較兩個值以計算大小較小的值,若輸入為 NaN則返回另一個值。

INumberBase<Char>.MultiplyAddEstimate(Char, Char, Char)

計算估計值為(left * right) + 。 addend

INumberBase<Char>.One

取得該類型的數值 1

INumberBase<Char>.Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

將字元範圍剖析為值。

INumberBase<Char>.Parse(String, NumberStyles, IFormatProvider)

將字串剖析成值。

INumberBase<Char>.Radix

取得型別的進位或基底。

INumberBase<Char>.TryConvertFromChecked<TOther>(TOther, Char)

以UTF-16程式代碼單位表示字元。

INumberBase<Char>.TryConvertFromSaturating<TOther>(TOther, Char)

以UTF-16程式代碼單位表示字元。

INumberBase<Char>.TryConvertFromTruncating<TOther>(TOther, Char)

以UTF-16程式代碼單位表示字元。

INumberBase<Char>.TryConvertToChecked<TOther>(Char, TOther)

嘗試將目前類型的實例轉換成另一個類型,針對落在目前類型可表示範圍以外的任何值擲回溢位例外狀況。

INumberBase<Char>.TryConvertToSaturating<TOther>(Char, TOther)

嘗試將目前類型的實例轉換成另一個類型,使任何落在目前類型可表示範圍以外的值飽和。

INumberBase<Char>.TryConvertToTruncating<TOther>(Char, TOther)

嘗試將目前類型的實例轉換成另一個類型,截斷落在目前類型可表示範圍以外的任何值。

INumberBase<Char>.TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Char)

以UTF-16程式代碼單位表示字元。

INumberBase<Char>.TryParse(String, NumberStyles, IFormatProvider, Char)

以UTF-16程式代碼單位表示字元。

INumberBase<Char>.Zero

取得該類型的數值 0

IParsable<Char>.Parse(String, IFormatProvider)

將字串剖析成值。

IParsable<Char>.TryParse(String, IFormatProvider, Char)

以UTF-16程式代碼單位表示字元。

IShiftOperators<Char,Int32,Char>.LeftShift(Char, Int32)

將指定數量留下的值移位。

IShiftOperators<Char,Int32,Char>.RightShift(Char, Int32)

將值向右移位指定的數量。

IShiftOperators<Char,Int32,Char>.UnsignedRightShift(Char, Int32)

將值向右移位指定的數量。

ISpanFormattable.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

嘗試將目前實例的值格式化為提供的字元範圍。

ISpanParsable<Char>.Parse(ReadOnlySpan<Char>, IFormatProvider)

將字元範圍剖析為值。

ISpanParsable<Char>.TryParse(ReadOnlySpan<Char>, IFormatProvider, Char)

以UTF-16程式代碼單位表示字元。

ISubtractionOperators<Char,Char,Char>.CheckedSubtraction(Char, Char)

減去兩個值來計算其差異。

ISubtractionOperators<Char,Char,Char>.Subtraction(Char, Char)

減去兩個值來計算其差異。

IUnaryNegationOperators<Char,Char>.CheckedUnaryNegation(Char)

計算值的已核取一元否定。

IUnaryNegationOperators<Char,Char>.UnaryNegation(Char)

計算值的一元負值。

IUnaryPlusOperators<Char,Char>.UnaryPlus(Char)

計算值的一元加號。

IUtf8SpanFormattable.TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider)

嘗試將目前實例的值格式化為UTF-8到提供的位元組範圍。

IUtf8SpanParsable<Char>.Parse(ReadOnlySpan<Byte>, IFormatProvider)

以UTF-16程式代碼單位表示字元。

IUtf8SpanParsable<Char>.TryParse(ReadOnlySpan<Byte>, IFormatProvider, Char)

以UTF-16程式代碼單位表示字元。

適用於

執行緒安全性

此類型的所有成員都是安全線程。 看似修改實例狀態的成員實際上會傳回以新值初始化的新實例。 如同任何其他類型,讀取和寫入包含此類型實例的共用變數必須受到鎖定的保護,以確保線程安全性。

另請參閱