使用数组从VBScript调用C#中的COM

使用数组从VBScript调用C#中的COM,c#,com,vbscript,C#,Com,Vbscript,在第一个示例中,使用字符串从VBScript调用用C#编写的COM函数是可以的 public bool IsEqualTo(string firstString, string SecondString) { bool areEqual = String.Equals(firstString, SecondString, StringComparison.Ordinal); if (areEqual){ return true; }

在第一个示例中,使用字符串从VBScript调用用C#编写的COM函数是可以的

    public bool IsEqualTo(string firstString, string SecondString)
    {

    bool areEqual = String.Equals(firstString, SecondString, StringComparison.Ordinal);

    if (areEqual){

    return true;

    }

    else return false;

    }

VBScript: MsgBox oTestCom.IsEqualTo(one,one)
在第二个示例中,不确定如何传递和操作数组。最好使用数组、ArrayList还是Object

public Array SortAscending (Array firstArray)

{
firstArray.Sort;

return firstArray;

}


VBScript: arrout = oTestCom.SortAscending("car","plane","boat")
在C#中,使用
object
作为数组参数类型。在VBScript中,使用
array
函数构造数组。以下是一个例子:

C#代码:

VBScript代码:

Set obj=CreateObject(“MySampleComX.Class1”)
arr=数组(3,1,2)
obj.sortintarr数组
MsgBox连接(arr)“输出”1 2 3

请试试这个,我试过了,可以工作了

C#代码

输出为“3 1 2”,所以不确定调用或函数是否工作。
using System;
using System.Linq;
using System.Runtime.InteropServices;

namespace MySampleComX
{
    [ComVisible(true)]
    public class Class1
    {
        public void SortIntArray(ref object array)
        {
            if (array.GetType() != typeof(object[])) 
            {
                throw new ArgumentException("Argument must be an array of integers");
            }
            array = ((object[]) array).OrderBy(Convert.ToInt32).ToArray();
        }
    }
}
   public object[] TestAray(ref object array)
   {
               
          if (array.GetType() != typeof(object[]))
          {
              throw new ArgumentException("Argument must be an array of integers");
          }
          var StrArray = ((object[])array).Cast<string>().ToArray();
          string[] res = StrArray;
                   
    
          for (int i = 0; i < res.Length; i++)
          {
              string tids;
              tids = Convert.ToString(res[i]);                  
           }        
    }
set obj=createObject("JustLib.TP_RateSchedules")
dim a
a=Array("5","10","15","20")
obj.TestAray(a)