What is a String[*] and how do I cast it?

前端 未结 2 933
说谎
说谎 2021-01-21 04:57

I\'m currently in the unfortunate position of having to call a VBA macro from C#, via the COM Interop. The macro returns an array of strings and looks something like:

         


        
2条回答
  •  余生分开走
    2021-01-21 05:26

    Your code was

    var result = (string[])xlApp.Run("Foo", ... missing args ...);
    

    As you have pointed out there is different behaviour with a 1-based array, with a zero-based array in VB your code does work.

    You can get at the data like this

    var result = (Array)xlApp.Run("Foo", ... missing args ...);
    
    var stringsResult = result.Cast[];
    

    This gives you an IEnumerable of string

提交回复
热议问题