SPRoleDefinitionCollection.Count property

Gets the number of role definitions in the collection.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Overrides ReadOnly Property Count As Integer
    Get
'Usage
Dim instance As SPRoleDefinitionCollection
Dim value As Integer

value = instance.Count
public override int Count { get; }

Property value

Type: System.Int32
A 32-bit integer that indicates the number of role definitions.

Implements

ICollection.Count

Examples

The following code example returns the number of role definitions from a specified Web site that has unique role definitions.

using(SPSite oSiteCollection = new SPSite("http://Server_Name/Subsite1"))
{
    using (SPWeb oWebsite = oSiteCollection.OpenWeb())
    {

        if (oWebsite.HasUniqueRoleDefinitions)
        {
            int intRoleDefinitionCount = oWebsite.RoleDefinitions.Count;
        }
    }
}
Using oSiteCollection As New SPSite("http://Server_Name/Subsite1")
   Using oWebsite As SPWeb = oSiteCollection.OpenWeb()

      If oWebsite.HasUniqueRoleDefinitions Then
         Dim intRoleDefinitionCount As Integer = oWebsite.RoleDefinitions.Count
      End If
   End Using
End Using

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

See also

Reference

SPRoleDefinitionCollection class

SPRoleDefinitionCollection members

Microsoft.SharePoint namespace