---
source_url: https://www.pubnub.com/docs/sdks/c-sharp/api-reference/channel-groups
title: Channel Groups API for C# SDK
updated_at: 2026-06-19T11:36:49.887Z
sdk_name: PubNub C# SDK
sdk_version: 8.3.0
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Channel Groups API for C# SDK

PubNub C# SDK, use the latest version: 8.3.0

Install:

```bash
dotnet add package PubNub@8.3.0
```

[Channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups) allow PubNub developers to bundle thousands of [channels](https://www.pubnub.com/docs/general/channels/overview) into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

:::note Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
:::

:::tip Request execution
Use `try`/`catch` when working with the C# SDK.
If a request has invalid parameters (for example, a missing required field), the SDK throws an exception. If the request reaches the server but fails (server error or network issue), the error details are available in the returned `status`.
```csharp
try
{
    PNResult<PNPublishResult> publishResponse = await pubnub.Publish()
        .Message("Why do Java developers wear glasses? Because they can't C#.")
        .Channel("my_channel")
        .ExecuteAsync();
    PNStatus status = publishResponse.Status;
    Console.WriteLine("Server status code : " + status.StatusCode.ToString());
}
catch (Exception ex)
{
    Console.WriteLine($"Request can't be executed due to error: {ex.Message}");
}
```
:::

## Add channels to a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the PubNub [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function adds channels to a channel group.

### Method(s)

Use the following method in the C# SDK:

:::note Maximum number of channels
You can add up to 200 channels to a channel group per API call.
:::

```csharp
pubnub.AddChannelsToChannelGroup()
        .ChannelGroup(string)
        .Channels(Array)
        .QueryParam(Dictionary<string,object>)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| ChannelGroup | string | Yes |  | The channel group to add the channels to. |
| Channels | Array | Yes |  | The channels to add to the channel group. |
| QueryParam | Dictionary<string, | Optional |  | Dictionary `object` to pass name/value pairs as query `string` params with PubNub URL request for debug purpose. |
| Async | PNCallback | Optional |  | PNCallback of type PNChannelGroupsAddChannelResult. This parameter is deprecated and will be removed in a future version. Please use the `ExecuteAsync` parameter instead. |
| Execute | PNCallback | Yes |  | `PNCallback` of type `PNChannelGroupsAddChannelResult`. |
| ExecuteAsync | None | Optional |  | Returns `PNResult<PNChannelGroupsAddChannelResult>`. |

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

#### Add channels

```csharp
using PubnubApi;

//Create configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo"
};
//Create a new PubNub instance
Pubnub pubnub = new Pubnub(pnConfiguration);
        
try
{
    PNResult<PNChannelGroupsAddChannelResult> cgAddChResponse = await pubnub.AddChannelsToChannelGroup()
        .ChannelGroup("myChannelGroup")
        .Channels(new string[] { "channel1", "channel2", "channel3" })
        .ExecuteAsync();

    PNChannelGroupsAddChannelResult cgAddChResult = cgAddChResponse.Result;
    PNStatus cgAddChStatus = cgAddChResponse.Status;

    if (!cgAddChStatus.Error && cgAddChResult != null)
    {
        Console.WriteLine("Channels successfully added to the channel group.");
    }
    else
    {
        Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(cgAddChStatus));
    }
}
catch (Exception ex)
{
    Console.WriteLine($"Request cannot be executed due to error: {ex.Message}");
}
```

### Returns

The `AddChannelsToChannelGroup()` operation returns a `PNResult<PNChannelGroupsAddChannelResult>` which contains the following properties:

| Property Name | Type | Description |
| --- | --- | --- |
| `Result` | PNChannelGroupsAddChannelResult | Returns a `PNChannelGroupsAddChannelResult` object. |
| `Status` | PNStatus | Returns a `PNStatus` object. |

`PNChannelGroupsAddChannelResult` contains the following properties:

| Property Name | Type | Description |
| --- | --- | --- |
| `PNChannelGroupsAddChannelResult` | Object | Returns empty object. |
| `PNStatus` | Object | Returns status of request if error occurred or not. |

## List channels in a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function lists all channels in a channel group.

### Method(s)

Use the following method in the C# SDK:

```csharp
pubnub.ListChannelsForChannelGroup()
        .ChannelGroup(string)
        .QueryParam(Dictionary<string,object>)
```

| Parameter | Description |
| --- | --- |
| `ChannelGroup` *Type: string | The channel group for which to list channels. |
| `QueryParam`Type: Dictionary`<string, object>` | Dictionary `object` to pass name/value pairs as query `string` params with PubNub URL request for debug purpose. |
| AsyncType: PNCallback | PNCallback of type PNChannelGroupsAllChannelsResult. This parameter is deprecated and will be removed in a future version. Please use the `ExecuteAsync` parameter instead. |
| `Execute` *Type: PNCallback | `PNCallback` of type `PNChannelGroupsAllChannelsResult`. |
| `ExecuteAsync`Type: None | Returns `PNResult<PNChannelGroupsAllChannelsResult>`. |

### Sample code

#### List channels

```csharp
using PubnubApi;

//Create configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo"
};
//Create a new PubNub instance
Pubnub pubnub = new Pubnub(pnConfiguration);
        
PNResult<PNChannelGroupsAllChannelsResult> cgListChResponse = await pubnub.ListChannelsForChannelGroup()
    .ChannelGroup("cg1")
    .ExecuteAsync();
```

### Returns

The `ListChannelsForChannelGroup()` operation returns a `PNChannelGroupsAllChannelsResult` which contains the following properties:

| Property Name | Type | Description |
| --- | --- | --- |
| `Result` | PNChannelGroupsAllChannelsResult | Returns a `PNChannelGroupsAllChannelsResult` object. |
| `Status` | PNStatus | Returns a `PNStatus` object. |

`PNChannelGroupsAllChannelsResult` contains the following property:

| Property Name | Type | Description |
| --- | --- | --- |
| `Channels` | List`<string>` | List of `channels` of a `channel group`. |

## Remove channels from a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function removes channels from a channel group.

### Method(s)

Use the following method in the C# SDK:

```csharp
pubnub.RemoveChannelsFromChannelGroup()
        .ChannelGroup(string)
        .Channels(Array)
        .QueryParam(Dictionary<string,object>)
```

| Parameter | Description |
| --- | --- |
| `ChannelGroup` *Type: string | The channel group from which to remove the channels. |
| `Channels` *Type: Array | The channels to remove from the channel group. |
| `QueryParam`Type: Dictionary`<string, object>` | Dictionary `object` to pass name/value pairs as query `string` params with PubNub URL request for debug purpose. |
| AsyncType: PNCallback | PNCallback of type PNChannelGroupsRemoveChannelResult. This parameter is deprecated and will be removed in a future version. Please use the `ExecuteAsync` parameter instead. |
| `Execute` *Type: PNCallback | `PNCallback` of type `PNChannelGroupsRemoveChannelResult`. |
| `ExecuteAsync`Type: None | Returns `PNResult<PNChannelGroupsRemoveChannelResult>`. |

### Sample code

#### Remove channels

```csharp
using PubnubApi;

//Create configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo"
};
//Create a new PubNub instance
Pubnub pubnub = new Pubnub(pnConfiguration);
        
PNResult<PNChannelGroupsRemoveChannelResult> rmChFromCgResponse = await pubnub.RemoveChannelsFromChannelGroup()
    .ChannelGroup("family")
    .Channels(new string[] {
        "son"
    })
    .ExecuteAsync();
```

### Returns

The `RemoveChannelsFromChannelGroup()` operation returns a `PNChannelGroupsAddChannelResult` which contains the following properties:

| Property Name | Type | Description |
| --- | --- | --- |
| `Result` | PNChannelGroupsRemoveChannelResult | Returns a `PNChannelGroupsRemoveChannelResult` object. |
| `Status` | PNStatus | Returns a `PNStatus` object. |

`PNChannelGroupsRemoveChannelResult` contains the following property:

| Property Name | Type | Description |
| --- | --- | --- |
| `PNChannelGroupsRemoveChannelResult` | Object | Returns empty object. |

## Delete a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function deletes a channel group.

### Method(s)

Use the following method in the C# SDK:

```csharp
pubnub.DeleteChannelGroup()
        .ChannelGroup(string)
        .QueryParam(Dictionary<string,object>)
```

| Parameter | Description |
| --- | --- |
| `ChannelGroup` *Type: string | The channel group to delete. |
| `QueryParam`Type: Dictionary`<string, object>` | Dictionary `object` to pass name/value pairs as query `string` params with PubNub URL request for debug purpose. |
| AsyncType: PNCallback | PNCallback of type PNChannelGroupsDeleteGroupResult. This parameter is deprecated and will be removed in a future version. Please use the `ExecuteAsync` parameter instead. |
| `Execute` *Type: PNCallback | `PNCallback` of type `PNChannelGroupsDeleteGroupResult`. |
| `ExecuteAsync`Type: None | Returns `PNResult<PNChannelGroupsAllChannelsResult>`. |

### Sample code

#### Delete channel group

```csharp
using PubnubApi;

//Create configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo"
};
//Create a new PubNub instance
Pubnub pubnub = new Pubnub(pnConfiguration);
        
PNResult<PNChannelGroupsDeleteGroupResult> delCgResponse = await pubnub.DeleteChannelGroup()
    .ChannelGroup("family")
    .ExecuteAsync();
```

### Response

```json
{
    "status" : 200,
    "message" : "OK",
    "service" : "channel-registry",
    "error" : False
}
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.