【问题标题】:What's the difference between `?` and `Debug.Print` in VB.Net immediate window?VB.Net即时窗口中的`?`和`Debug.Print`有什么区别?
【发布时间】:2012-01-23 15:33:27
【问题描述】:

谁能解释以下即时窗口行为:

Debug.Print mDb.DatabaseOptions
Method arguments must be enclosed in parentheses.

Debug.Print(mDb.DatabaseOptions)
Value of type 'DatabaseOptions' cannot be converted to 'String'.

? mDb.DatabaseOptions
{Microsoft.SqlServer.Management.Smo.DatabaseOptions}
    AnsiNullDefault: False
    ...
    UserData: Nothing

根据MS documentation

问号 (?) 是 Debug.Print 的别名

这显然不是 100% 正确的,因为这两个语句在上面的示例中表现出不同的行为。如果有什么不同,我使用的是 VB 2008 的 Express Edition。

【问题讨论】:

    标签: vb.net smo


    【解决方案1】:

    Debug.Print 方法和Debug.Print 命令之间存在区别。

    命令通常在 Command.Window 中输入。要在即时窗口中输入命令,您需要在命令名称前附加 >,这样:

    ?mDb.DatabaseOptions
    

    是命令的别名:

    >Debug.Print mDb.DatabaseOptions
    

    不是调用方法的别名:

    Debug.Print(mDb.DatabaseOptions)
    

    【讨论】:

      【解决方案2】:

      我们如何使“方法”的行为像命令一样? 我有一个像

      这样的变量
      Dictionary<string, Tuple<string, string, string, string>> results
      

      Debug.Print(results) 返回

      System.Collections.Generic.Dictionary`2[System.String,System.Tuple`4[System.String,System.String,System.String,System.String]]
      

      ...同时

      ?results
          [0]: {[stringKey, (stringT1, stringT2, stringT3, stringT4)]}
          [1]: {[stringKey, (stringT1, stringT2, stringT3, stringT4)]}
          ...
      

      我显然想要!

      【讨论】:

        猜你喜欢
        • 2011-04-08
        • 1970-01-01
        • 1970-01-01
        • 2011-04-21
        • 1970-01-01
        • 2010-09-23
        • 2018-10-23
        • 2017-01-09
        • 1970-01-01
        相关资源
        最近更新 更多