无法理解如何调用此功能

时间:2013-07-30 10:39:23

标签: c# asp.net

我在我的网络应用程序中添加了第三方dll。该功能的一部分看起来像这样

public InterestCategory[] gvc(string st)
{
    object[] results = this.Invoke("getit", new object[] {
                    st});
    return ((InterestCategory[])(results[0]));
}

你可以看到函数返回InterestCategory[]。当我检查(GoToDefinition)InterestCategory时,我可以看到这个

  public partial class InterestCategory
{
    private string descriptionField;
    public string Description
    {
        get
        {
            return this.descriptionField;
        }
        set
        {
            this.descriptionField = value;
        }
    }
}

现在在我的代码中,我试图像这样调用这个函数

  API.InterestCategory IC = new API.InterestCategory();
  IC  =    api.gvc(st);

它会抛出这样的错误

 Cannot implicitly convert type 'API.InterestCategory[]' to 'API.InterestCategory'  

任何人都可以告诉我调用此函数的正确程序是什么

5 个答案:

答案 0 :(得分:2)

IC应该是Api.InterestCategory的数组。相反,您将变量声明为Api.InterestCategory。尝试:

Api.InterestCategory[] IC = api.GetValidInterestsCategories(securityToken);

答案 1 :(得分:2)

该方法返回一个数组,因此您必须将结果分配给正确类型的变量:

InterestCategory[] ics = api.gvc(securityToken);

答案 2 :(得分:2)

您为变量指定了错误的类型。当函数返回数组InterestCategory时,您已告诉编译器要创建类型InterestCategory[]的单个变量。

将您的代码更改为此代码,它应该可以正常工作:

API.InterestCategory[] ICs;
ICs = api.gvc(securityToken);

答案 3 :(得分:1)

API.InterestCategory IC = new API.InterestCategory();

所以输入

IC = api.gvc错误,因为IC InterestCategory而非InterestCategory[]

尝试:

var IC = api.gvc(securityToken)

答案 4 :(得分:0)

你好你正在做的一切正确,但你得到的问题是由于你想要存储它的返回类型和变量不匹配..我不知道为什么你不能理解这个问题..它属于编程的基础知识。所以这样做。

api.InterestCategory[] ic = api.gvc(securityToken);
相关问题