【问题标题】:combobox items add (an item of a class) how to do this (see code inside)组合框项目添加(一个类的项目)如何做到这一点(见里面的代码)
【发布时间】:2014-04-20 23:19:19
【问题描述】:

所以我有 Visual Basic 的任务,我有一些关于这个设置的内容:

Me.ArticlesComboBox.Items.Add(New Article(code:="xxx", name:="xxxxx", unitPrice:=xxx)

我不明白 code:= 是什么意思? 我有一个类文章,其属性代码和名称为字符串,单位价格为十进制。

我遇到的错误是:'code' is not a parameter of 'Public Sub New()'.

欢迎所有帮助:)

【问题讨论】:

  • 我想你正在寻找这个:stackoverflow.com/questions/3936224/…
  • 我不确定这是否是我需要的,我只是觉得奇怪的是为什么 code:= 或 name:= 在那里。这有特殊含义/语法吗?
  • 是的。 code:=value 表示您正在设置方法的参数。例如,Public Sub MySub(code As String, name as String),您可以执行以下操作 - MySub(name:="xxx", code:="yyy")。请注意,它们现在的提供顺序与请求的顺序不同。
  • 如果 Article 类是您的,请发布其 ctor(Sub New)。否则 Intellisense 应该会告诉你参数需要如何创建它的实例

标签: vb.net


【解决方案1】:

错误是告诉你 Article 需要一个类似这样的构造函数

Public Sub New(code As String, name As String, unitPrice As Decimal)

End Sub

在构造函数中将变量分配给类的属性。

【讨论】:

  • 像这样:Public Class Article Public Property code As String Public Property name As String Public Property unitPrice As Decimal Public Sub New(C As String, N As String, uP As Decimal) code = C name = N unitPrice = uP End Sub End Class
猜你喜欢
  • 1970-01-01
  • 2012-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多