> For the complete documentation index, see [llms.txt](https://docs.gamechat.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gamechat.me/basics/game-chat-v3/game-chat-zhong-wen/kai-shi-shi-yong-v3/shi-yong-shi-li.md).

# 使用示例

## 示例

### Ncloudchat React 示例

完整的源码已经公开在 GitHub 上，您可以下载 GitHub 上的源码，也可以通过 <https://www.ncloudchat.com> 进行使用。

### 完整的示例代码

以下是访问、创建频道以及向创建的频道发送加入消息的示例代码：

```csharp

// 初始化
CloudChat nc = CloudChat.GetInstance();
await nc.initialize([PROJECT_ID]);
nc.dispatcher.onMessageReceived += e =>
{
    Console.WriteLine("received a new message: ", e);
};
await nc.Connect(
    userId: 'guest@company',
    name: 'Guest',
    profile: 'https://image_url',
    customField: 'json',
);
// 创建频道
var channel = await nc.createChannel(new CloudChatSDK.Channel
{
    name = "New Channel",
    type = "PUBLIC",    // PUBLIC or PRIVATE
    customField = "customField"
});
var channel = await nc.createChannel({type:'PUBLIC', name:'First Channel', customField:'customField'});
var channel_id = channel.createChannel.channel.id.ToString();
// 订阅频道
await nc.subscribe(channel_id);
// 发送消息
var response = await nc.sendMessage(
        channelId: channel_id, 
        type:"text", 
        content: message
    );
```
