2012-12-29 85 views
0

我想知道如何在VB.NET中做一个只读属性的接口?VB.NET接口属性与Getter,但没有安装程序

在C#中我会做这样的事情:

interface ISomething { 
    int PropNeeded { get; } 
} 

但是,当我尝试做相同的VB

Interface ISomething 
    Property PropNeeded() As Integer 
     Get 
     End Get 
    End Property 
End Interface 

我从Visual Studio 2010中此错误消息:“声明不能出现在接口体内假设接口结束

看起来像是逻辑,因为它就像我试图给一个实现Property ...但重要的是该物业没有Setter只有一个Getter。

您的帮助将不胜感激!

回答

2
Readonly Property PropNeeded() As Integer 
+0

谢谢,它确实很简单:P – HexaGridBrain

2
Interface ISomething 
     ReadOnly Property PropNeeded() As Integer 
End Interface 

作为一个侧面说明,您可以使用C#VB的在线代码转换器。 Telerik code converter

+0

我想链接到Telerik代码转换器将是非常有用的,谢谢! – HexaGridBrain

+0

确实如此。对于C#中有经验的人和VB.NET中的新手而言,使生活变得轻松许多。还有其他在线转换器。 – Tilak