SortKey.KeyData 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得表示目前 SortKey 物件的位元組陣列。
public:
property cli::array <System::Byte> ^ KeyData { cli::array <System::Byte> ^ get(); };
public:
virtual property cli::array <System::Byte> ^ KeyData { cli::array <System::Byte> ^ get(); };
public byte[] KeyData { get; }
public virtual byte[] KeyData { get; }
member this.KeyData : byte[]
Public ReadOnly Property KeyData As Byte()
Public Overridable ReadOnly Property KeyData As Byte()
屬性值
Byte[]
表示目前 SortKey 物件的位元組陣列。
範例
下列程式代碼範例會顯示區分大小寫排序索引鍵的原始字串和對等字串和索引鍵數據,以及不區分大小寫的排序索引鍵。
// This code example demonstrates the
// GetSortKey() and ToString() methods, and the
// OriginalString and KeyData properties of the
// System.Globalization.SortKey class.
using System;
using System.Globalization;
class Sample
{
public static void Main()
{
CompareInfo cmpi = null;
SortKey sk1 = null;
SortKey sk2 = null;
string s = "ABC";
string ignoreCase = "Ignore case";
string useCase = "Use case ";
// Get a CompareInfo object for the English-Great Britain culture.
cmpi = CompareInfo.GetCompareInfo("en-GB");
// Get a sort key that ignores case for the specified string.
sk1 = cmpi.GetSortKey(s, CompareOptions.IgnoreCase);
// Get a sort key with no compare option for the specified string.
sk2 = cmpi.GetSortKey(s);
// Display the original string.
Console.WriteLine("Original string: \"{0}\"", sk1.OriginalString);
Console.WriteLine();
// Display the string equivalent of the two sort keys.
Console.WriteLine("CompareInfo (culture) name: {0}", cmpi.Name);
Console.WriteLine("ToString - {0}: \"{1}\"", ignoreCase, sk1.ToString());
Console.WriteLine("ToString - {0}: \"{1}\"", useCase, sk2.ToString());
Console.WriteLine();
// Display the key data of the two sort keys.
DisplayKeyData(sk1, ignoreCase);
DisplayKeyData(sk2, useCase);
}
public static void DisplayKeyData(SortKey sk, string title)
{
Console.Write("Key Data - {0}: ", title);
foreach (byte keyDatum in sk.KeyData)
Console.Write("0x{0} ", (uint)keyDatum);
Console.WriteLine();
}
}
/*
This code example produces the following results:
Original string: "ABC"
CompareInfo (culture) name: en-GB
ToString - Ignore case: "SortKey - 2057, IgnoreCase, ABC"
ToString - Use case : "SortKey - 2057, None, ABC"
Key Data - Ignore case: 0x14 0x2 0x14 0x9 0x14 0x10 0x1 0x1 0x1 0x1 0x0
Key Data - Use case : 0x14 0x2 0x14 0x9 0x14 0x10 0x1 0x1 0x18 0x18 0x18 0x1 0x1 0x0
*/
' This code example demonstrates the
' GetSortKey() and ToString() methods, and the
' OriginalString and KeyData properties of the
' System.Globalization.SortKey class.
Imports System.Globalization
Class Sample
Public Shared Sub Main()
Dim cmpi As CompareInfo = Nothing
Dim sk1 As SortKey = Nothing
Dim sk2 As SortKey = Nothing
Dim s As String = "ABC"
Dim ignoreCase As String = "Ignore case"
Dim useCase As String = "Use case "
' Get a CompareInfo object for the English-Great Britain culture.
cmpi = CompareInfo.GetCompareInfo("en-GB")
' Get a sort key that ignores case for the specified string.
sk1 = cmpi.GetSortKey(s, CompareOptions.IgnoreCase)
' Get a sort key with no compare option for the specified string.
sk2 = cmpi.GetSortKey(s)
' Display the original string.
Console.WriteLine("Original string: ""{0}""", sk1.OriginalString)
Console.WriteLine()
' Display the string equivalent of the two sort keys.
Console.WriteLine("CompareInfo (culture) name: {0}", cmpi.Name)
Console.WriteLine("ToString - {0}: ""{1}""", ignoreCase, sk1.ToString())
Console.WriteLine("ToString - {0}: ""{1}""", useCase, sk2.ToString())
Console.WriteLine()
' Display the key data of the two sort keys.
DisplayKeyData(sk1, ignoreCase)
DisplayKeyData(sk2, useCase)
End Sub
Public Shared Sub DisplayKeyData(ByVal sk As SortKey, ByVal title As String)
Console.Write("Key Data - {0}: ", title)
Dim keyDatum As UInteger
For Each keyDatum In sk.KeyData
Console.Write("0x{0} ", CUInt(keyDatum))
Next keyDatum
Console.WriteLine()
End Sub
End Class
'
'This code example produces the following results:
'
'Original string: "ABC"
'
'CompareInfo (culture) name: en-GB
'ToString - Ignore case: "SortKey - 2057, IgnoreCase, ABC"
'ToString - Use case : "SortKey - 2057, None, ABC"
'
'Key Data - Ignore case: 0x14 0x2 0x14 0x9 0x14 0x10 0x1 0x1 0x1 0x1 0x0
'Key Data - Use case : 0x14 0x2 0x14 0x9 0x14 0x10 0x1 0x1 0x18 0x18 0x18 0x1 0x1 0x0
'
備註
如需比較字串中 屬性所 KeyData 傳回數據的詳細資訊,請參閱 SortKey 類別主題。