follow https://cloud.google.com/pubsub/docs/reference/libraries#cloud-console
  1. Install-Package Google.Cloud.PubSub.V1 -Pre  
  2.   
  3. using Google.Cloud.PubSub.V1;  
  4. using Grpc.Core;  
  5. using System;  
  6.   
  7. public class CreateTopicSample  
  8. {  
  9.     public Topic CreateTopic(string projectId, string topicId)  
  10.     {  
  11.         PublisherServiceApiClient publisher = PublisherServiceApiClient.Create();  
  12.         var topicName = TopicName.FromProjectTopic(projectId, topicId);  
  13.         Topic topic = null;  
  14.   
  15.         try  
  16.         {  
  17.             topic = publisher.CreateTopic(topicName);  
  18.             Console.WriteLine($"Topic {topic.Name} created.");  
  19.         }  
  20.         catch (RpcException e) when (e.Status.StatusCode == StatusCode.AlreadyExists)  
  21.         {  
  22.             Console.WriteLine($"Topic {topicName} already exists.");  
  23.         }  
  24.         return topic;  
  25.     }  
  26. }