Search code examples
c#visual-c++com

How to return a list of strings in C#


How do I store and return a List of Strings?

I have written a function which returns a collection of strings and I want to prepare a COM for it, and need to consume it (to get the returned list) in VC++ where I can extend some functionality using that list of strings.


Solution

  • List<string> or string[] are the best options.

    Here is a sample method that returns list of strings :

    public static List<string> GetCities()
    {
      List<string> cities = new List<string>();
      cities.Add("Istanbul");
      cities.Add("Athens");
      cities.Add("Sofia");
      return cities;
    }