无法从C#类获取静态类变量到VB.NET类

时间:2013-01-21 06:53:27

标签: c# vb.net static-members

c#c​​lass:

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是一个类(实现INterFace)

不知道为什么我看不到这个 - 我收到一个错误: “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
    ...
    }

1 个答案:

答案 0 :(得分: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