3
當我在Visual Studio的Watch Window中查看對象時,我認爲C#對象的所有非公開(即私人,受保護,內部和內部受保護)成員都屬於「非公開成員」。但後來,我發現此代碼anamoly:Visual Studio的Watch窗口中的「非公共成員」節點有什麼?
class HashDerived : System.Security.Cryptography.HashAlgorithm { ... }
HashAlgorithm hash1 = new HashDerived();
HashAlgorithm hash2 = new System.Security.Cryptography.SHA1Cng();
hash1
的‘非公共成員’看起來是這樣的:
而hash2
的‘非公共成員’看起來是這樣的:
所以它只是似乎是HASH1,該private
字段(m_bDisposed)出現在「非公開成員」節點下,其中對於hash2,甚至protected
和protected internal
成員(如「HashSizeValue」和「HashValue」)出現在其中。
爲什麼會發生這種情況?這種行爲背後的規則是什麼?
SHA1Cng被聲明**密封**。因此,其受保護的成員不再可以被任何派生類訪問。 – 2012-07-21 20:07:32