【问题标题】:What is the use of := in this program? [duplicate]:= 在这个程序中有什么用? [复制]
【发布时间】:2010-11-09 14:03:57
【问题描述】:

可能重复:
VB.NET := Operator

昨天我在浏览Microsoft® Agent 代码 sn-ps 时看到 := 在调用函数时使用。

我尝试在 Google 中搜索它,但找不到任何相关内容。

是否因为调用了 COM 库的函数而使用了 :=?

代码:

Public Class Form1

    Dim agent As AgentObjects.Agent
    Dim merlin As AgentObjects.IAgentCtlCharacter

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        agent.Characters.Unload("merlin")
        merlin = Nothing
        agent = Nothing
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        agent = New AgentObjects.Agent
        agent.Connected = True
        agent.Characters.Load(CharacterID:="Merlin", LoadKey:="merlin.acs")
        merlin = agent.Characters(CharacterID:="Merlin")
        agent.PropertySheet.Visible = True
    End Sub

    Public Sub IntroMerlin()
        Dim strName As String
        With merlin
            'Display character.
            .Show()
            'Make the character play an animation.
            .Play(Animation:="Greet")
            .Play(Animation:="Restpose")
            .Speak(Text:="Hello!")
            .Play(Animation:="Announce")
            .Speak(Text:="I am Merlin.")
            .Play(Animation:="Pleased")
            .Speak(Text:="It is nice to meet you.")
        End With
    End Sub
End Class

谢谢。

【问题讨论】:

  • @Georg Fritzsche 是的,它是 VB.NET := 运算符的副本,我尝试在 C# 中搜索 := 运算符而不是 Vb.net 中的 := 运算符。我真是太愚蠢了。甚至我也投票结束了这个问题。
  • 你很诚实!我也会投票关闭。

标签: vb.net com microsoft-agent


【解决方案1】:

那些是named parameters。如果一个函数有很长的默认参数列表,它会特别方便。您只需命名要为其提供值的那些,而不必处理位置要求。

【讨论】:

    【解决方案2】:

    这就是您在 VB/VBA/VB.NET 中指定“命名参数”的方式——通过参数名称而不是位置来提供参数。例如,请参阅this blog post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      相关资源
      最近更新 更多