This is a piece of code I tend to need every few months but always need a few minutes to find. So I'm just going to put it on here for mine and others future reference.

The code returns a KeyValuePair list of all options in a CRM optionset.

public static List<KeyValuePair<string, int>> GetOptionSets(string entityName, string attributeName, IOrganizationService service)
{
    string AttributeName = attributeName;
    string EntityLogicalName = entityName;
    RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest
    {
        EntityFilters = EntityFilters.All,
        LogicalName = EntityLogicalName
    };
    RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);
    Microsoft.Xrm.Sdk.Metadata.EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata;
    Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => String.Equals(attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata;
    Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata options = picklistMetadata.OptionSet;
    var ret = options.Options
        .Where(x => x.Label != null && x.Label.UserLocalizedLabel != null && x.Label.UserLocalizedLabel.Label != null && x.Value.HasValue)
        .Select(x => new KeyValuePair<string, int>(x.Label.UserLocalizedLabel.Label, x.Value.Value))
        .ToList();

    return ret;
}

To use it call it as such:

GetOptionSets(Account.EntityLogicalName, "cst_sttributeWithOptionset", serviceContext.Instance);