【问题标题】:Errors on vb property variables when I build a project构建项目时 vb 属性变量的错误
【发布时间】:2018-01-30 18:32:39
【问题描述】:

我工作的公司最近有一个程序员离职,他用 VB 做了一个 WPF 项目,但现在已经不能工作了。我被指派修复这个项目。我注意到的第一件事是他拥有的这些属性变量的构建错误。他们看起来像这样

Public Property BasePath As String = "this is a string to db properties"
Public Property header As New CurrentRun_HDR
Public Property PageHolder As New List(Of Page)
Public Property ScheduleHolder As New List(Of Page)
Public Property HeaderHolder As New List(Of Page)
Private Property LastUpdate As DateTime = Now
Private Property RefreshDate As DateTime = Now
Public Property MouseEnabled As Boolean = True

Visual Studio 2008 说属性需要获取、设置,所以我通过执行这样的操作来满足第一个。

Private _Prop2 As String = "this is a string to db properties"
    Property BasePath() As String
        Get
            Return _Prop2
        End Get
        Set(ByVal value As String)
            _Prop2 = value
        End Set
    End Property

我不确定如何修复其他错误,例如下一个

Public Property header As New CurrentRun_HDR 表示 new 在这种情况下无效。当我用谷歌搜索它时,它说你可以像这段代码一样自动实现属性,但它们会在构建时抛出错误,任何帮助将不胜感激。我在 Visual Studio 2008 中使用 .Net Framework 3.5

我去过这个site

【问题讨论】:

  • 我认为自动实现属性是在 VS 2010 中引入的,那么它是如何编译的?
  • @Plutonix 正确 - 在 VS 2010 中添加了自动实现属性。
  • 有趣我不确定,但我会尝试在 vs2010 中打开它,看看会发生什么。那家伙刚刚说他们使用 vs 2008,我相信他们的话

标签: .net wpf vb.net


【解决方案1】:

语法应该是这样的:

Public Property PageHolder As List(Of Page) = New List(Of Page)

更多示例请参见this question

【讨论】:

  • 没用:这并没有解决 Visual Studio 版本不兼容的问题,而且它比上面使用的大致等效的语法更冗长。 Public Property ... As New List(Of ...) 是完美的。
猜你喜欢
  • 2017-12-10
  • 1970-01-01
  • 1970-01-01
  • 2014-04-05
  • 2020-07-06
  • 1970-01-01
  • 2013-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多