2012-08-10 46 views
2

我是一個ASP MVC 3 noobie工作我的方式通過音樂商店教程,但翻譯萬事成VB(我在VB店工作)。如何翻譯這個C#屬性到VB

本教程中有一行:

public class Album 
{ 
    [Required(ErrorMessage = "An Album Title is required")] 
    [StringLength(160)] 
    public string Title  { get; set; } 
} 

如何翻譯成VB呢?顯而易見的選擇是:

Public Class Album 

    <Required(ErrorMessage = "Price is required")> //Compiler says:'ErrorMessage' is not declared. It may be inaccessible due to its protection level. 
    <StringLength(160)> 
    Property Title As String 
    Property Price As Decimal 

End Class 

但編譯器正在拋出一個錯誤(如上所示)。它似乎認爲錯誤信息是專輯的財產。

我能做些什麼來解決這個問題?

+0

是否VB.Net有像C#*使用*指令?如果是這樣,你缺少一個對這個代碼? – 2012-08-10 16:38:55

+0

akh2103完全轉換的方法是下面你可以讓我知道是否適合你..?感謝 – MethodMan 2012-08-10 16:42:51

回答

9

這應該是:

<Required(ErrorMessage := "Price is required")> _ 
<StringLength(160)> _ 

退房的VB documentation on attributes以獲取更多信息。

+0

感謝,這工作。 – bernie2436 2012-08-10 16:46:39

0
Public Class Album 
    <Required(ErrorMessage := "An Album Title is required")> _ 
    <StringLength(160)> _ 
    Public Property Title() As String 
     Get 
      Return m_Title 
     End Get 
     Set 
      m_Title = Value 
     End Set 
    End Property 
    Private m_Title As String 
End Class