Class CertificateNameCollection
Represents a collection of CertificateName objects.
Namespace
Assembly
System.dll (in System.dll)
Syntax
public sealed class CertificateNameCollection : System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
Remarks
The CertificateNameCollection class is used to store and manage a list of certificate names. Each name in the collection is represented by a CertificateName object. This collection is often used in scenarios involving certificate validation, such as when specifying the acceptable names for a server's SSL/TLS certificate.
You can add, remove, and access CertificateName objects within this collection. The collection implements several standard .NET interfaces, including ICollection, IEnumerable, and IList, providing familiar methods for iteration and manipulation.
Inheritance Hierarchy
System.Object
CertificateNameCollection
Thread Safety
Public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.
Example
using System;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class CertificateNameCollectionExample
{
public static void Main(string[] args)
{
// Create a new CertificateNameCollection
CertificateNameCollection certNames = new CertificateNameCollection();
// Add some certificate names
certNames.Add(new CertificateName("www.example.com"));
certNames.Add(new CertificateName("*.example.org", CertificateNameType.Wildcard));
Console.WriteLine($"Number of certificate names: {certNames.Count}");
// Iterate through the collection
Console.WriteLine("Certificate Names:");
foreach (CertificateName cn in certNames)
{
Console.WriteLine($"- {cn.Name} (Type: {cn.Type})");
}
// Check if a specific name exists
if (certNames.Contains(new CertificateName("www.example.com")))
{
Console.WriteLine("\n'www.example.com' is in the collection.");
}
// Remove a certificate name
certNames.Remove(new CertificateName("*.example.org", CertificateNameType.Wildcard));
Console.WriteLine($"\nAfter removing '*.example.org', count is: {certNames.Count}");
}
}
Requirements
Client: Supported in: .NET Framework 4.5, .NET Framework 4.0, .NET Framework 3.5, .NET Framework 3.0, .NET Framework 2.0
Server: Supported in: .NET Framework 4.5, .NET Framework 4.0, .NET Framework 3.5, .NET Framework 3.0, .NET Framework 2.0
Namespace: System.Net.Security
Assembly: System.dll