0

c#类:

public class AClass<T> where T : INterFace
{
  public static float m_var = 0.91F;
...
}

VB.NET 类

Public Class AnotherClass
...
Public ReadOnly Property V As Single
Get
   Return AClass(Of XX).m_var
End Get
End Property
End Class

XX 是一个类(实现了接口)

不知道为什么我看不到这个 - 我收到一个错误:“ m_var is not a member of AClass(Of XX)

我也用 c# 版本尝试过:

public class AClass<T> where T : INterFace
    {
      private const float m_var = 0.91F;
public static float VV { get { return m_var ; } }// change name in VB as needed
    ...
    }
4

1 回答 1

0

这很好用,注意 [INterface] 上的括号,因为它是 VB 中的保留字(不像 C# 那样区分大小写)

C#

public interface INterface
{
}

public class AClass<T> where T : INterface
{
    public static float m_var = 0.91F;
}

VB

添加对 C# 项目的引用

Imports MyCSharpNamespace

Public Class AnotherClass

    Public ReadOnly Property V As Single
        Get
            Return AClass(Of XX).m_var
        End Get
    End Property

End Class

Public Class XX
    Implements [INterface]


End Class
于 2013-01-21T08:48:54.193 回答