MSDN Library

X509Certificate2.ExtensionCount Property

Namespace: System.Net.Security

Assembly: System.Security.Cryptography.X509Certificates.dll

Inheritance: Object > X509Certificate > X509Certificate2

Applies to: .NET Core 2.0, .NET Framework 4.5, .NET Standard 1.3, Xamarin.Android 8.0, Xamarin.iOS 10.14, .NET 5+

Syntax

public int ExtensionCount { get; }

Property Value

System.Int32

The number of extensions in the certificate.

Remarks

The ExtensionCount property returns the total number of extensions associated with the X509Certificate2 object. Extensions provide additional information about the certificate beyond the standard fields, such as certificate policies, subject alternative names, or key usage constraints.

If a certificate has no extensions, this property will return 0. You can iterate through the extensions of a certificate using the Extensions property, which returns an X509ExtensionCollection.

Example

The following example demonstrates how to retrieve the number of extensions in an X509Certificate2 object.


// Assume 'certificate' is an initialized X509Certificate2 object
using System.Security.Cryptography.X509Certificates;

int extensionCount = certificate.ExtensionCount;

if (extensionCount > 0)
{
    Console.WriteLine("The certificate has {0} extensions.", extensionCount);
}
else
{
    Console.WriteLine("The certificate has no extensions.");
}
                    

Requirements

Client: Supported in Windows 8.1, Windows 10, Windows 11.
Server: Supported in Windows Server 2012 R2, Windows Server 2016, Windows Server 2019, Windows Server 2022.
.NET: Supported in .NET Framework 4.5, .NET Core 2.0, .NET Standard 1.3, .NET 5 and later versions.

See Also