共用方式為


RegistryKey.ValueCount 屬性

定義

擷取機碼中值的計數。

public:
 property int ValueCount { int get(); };
public int ValueCount { get; }
member this.ValueCount : int
Public ReadOnly Property ValueCount As Integer

屬性值

機碼中的名稱/值組的數目。

例外狀況

使用者不具有機碼的讀取權限。

正接受管理的 RegistryKey 已經關閉 (關閉的機碼無法存取)。

使用者沒有必要的登錄權限。

發生系統錯誤,例如,目前的機碼已經刪除。

範例

此程式代碼範例是針對 類別提供的較大範例的 RegistryKey 一部分。

// Print the information from the Test9999 subkey.
Console::WriteLine( "There are {0} subkeys under Test9999.", test9999->SubKeyCount.ToString() );
array<String^>^subKeyNames = test9999->GetSubKeyNames();
for ( int i = 0; i < subKeyNames->Length; i++ )
{
   RegistryKey ^ tempKey = test9999->OpenSubKey( subKeyNames[ i ] );
   Console::WriteLine( "\nThere are {0} values for {1}.", tempKey->ValueCount.ToString(), tempKey->Name );
   array<String^>^valueNames = tempKey->GetValueNames();
   for ( int j = 0; j < valueNames->Length; j++ )
   {
      Console::WriteLine( "{0,-8}: {1}", valueNames[ j ], tempKey->GetValue( valueNames[ j ] )->ToString() );

   }
}
// Print the information from the Test9999 subkey.
Console.WriteLine("There are {0} subkeys under {1}.",
    test9999.SubKeyCount.ToString(), test9999.Name);
foreach(string subKeyName in test9999.GetSubKeyNames())
{
    using(RegistryKey
        tempKey = test9999.OpenSubKey(subKeyName))
    {
        Console.WriteLine("\nThere are {0} values for {1}.",
            tempKey.ValueCount.ToString(), tempKey.Name);
        foreach(string valueName in tempKey.GetValueNames())
        {
            Console.WriteLine("{0,-8}: {1}", valueName,
                tempKey.GetValue(valueName).ToString());
        }
    }
}
' Print the information from the Test9999 subkey.
Console.WriteLine("There are {0} subkeys under Test9999.", _
    test9999.SubKeyCount.ToString())
For Each subKeyName As String In test9999.GetSubKeyNames()
    Dim tempKey As RegistryKey = _
        test9999.OpenSubKey(subKeyName)
    Console.WriteLine(vbCrLf & "There are {0} values for " & _
        "{1}.", tempKey.ValueCount.ToString(), tempKey.Name)
    For Each valueName As String In tempKey.GetValueNames()
        Console.WriteLine("{0,-8}: {1}", valueName, _
            tempKey.GetValue(valueName).ToString())
    Next
Next

備註

每個登錄機碼都有一個未與任何名稱相關聯的預設值。 您可以使用 方法來設定 SetValue 這個未命名的值,並針對 指定 null 空字串 (“”“) name。 如果從未設定過預設值,它就不會參與屬性所 ValueCount 傳回的總計數;不過,一旦設定,它一律會計算。

適用於