【问题标题】:Convert InnerList from Vb to c#将 InnerList 从 Vb 转换为 c#
【发布时间】:2014-02-10 12:51:54
【问题描述】:

我正在尝试将一些 VB 代码转换为 C#;但是我遇到了一些麻烦,

这是我的 VB 代码:

 Default Public Property Item(ByVal index As Integer) As BiometrikBilgi
            Get
                Return MyBase.InnerList(index)
            End Get
            Set(ByVal value As BiometrikBilgi)
                MyBase.InnerList(index) = value
            End Set
        End Property

我使用了转换器,结果如下:

C#

public BiometrikBilgi this[int index]
{
    get { return base.InnerList[index]; }
    set { base.InnerList[index] = value; }

但是在 get {} 行编译器给出错误它说;

无法将类型“object”隐式转换为“BiometrikBilgi”。存在显式转换(您是否缺少演员表?)

我该如何解决这个问题?

【问题讨论】:

  • 我该如何解决这个问题? 无意冒犯,但是您阅读了错误消息吗?它告诉您您缺少从objectBiometrikBilgi 的演员表:-)

标签: c# vb.net get set


【解决方案1】:

base.InnerList[index] 的值显然是 object 类型,但您的属性返回 BiometrikBilgi

尝试转换你返回的值:

get { return (BiometrikBilgi)base.InnerList[index]; }

【讨论】:

    猜你喜欢
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多