简体   繁体   English

为什么需要VS的Immediate Window中的问号?

[英]Why do we need the question mark in Immediate Window of VS?

So, reading this documentation: https://learn.microsoft.com/en-us/visualstudio/ide/reference/immediate-window?view=vs-2022因此,阅读此文档: https://learn.microsoft.com/en-us/visualstudio/ide/reference/immediate-window?view=vs-2022

It looks like the question mark (?) is an alias for the command >Debug.Print , which basically, will evaluate the expression and show the result.看起来问号 (?) 是命令>Debug.Print的别名,它基本上会计算表达式并显示结果。

So, in debug mode, instead of running this:所以,在调试模式下,不要运行这个:

>Debug.Print DoSomething()

I can run this:我可以运行这个:

? DoSomething()

This is even better because I'm getting the autocomplete suggestions.这更好,因为我收到了自动完成建议。

Now, the issue is that I can run the same line without a command at all, and it does exactly the same:现在,问题是我完全可以在没有命令的情况下运行同一行,而且它的作用完全相同:

DoSomething()

So far looks like there is no need for the command >Debug.Print or the alias ?到目前为止看起来不需要命令>Debug.Print或别名? . .

At first, I suspected that using ?起初,我怀疑使用? will only print the result without changing the values, but this is not the case (When I assign a value to a variable using ? it is assigned and the new value is printed)只会在不更改值的情况下打印结果,但事实并非如此(当我使用?为变量赋值时,它被赋值并打印新值)

So, am I missing something here?那么,我在这里遗漏了什么吗? Are there any other differences between these 3 options?这三个选项之间还有其他区别吗?

According to the documentation, if you want to use Visual Studio command, you need to add greater than sign before the command.根据文档,如果要使用 Visual Studio 命令,需要在命令前添加大于号。 If you run 'Debug.Print' without adding greater than sign, you will get an error.如果您在不添加大于号的情况下运行“Debug.Print”,您将收到错误消息。 My point is that the question mark ('?') is unnecessary if you in the Immediate Window, it is used to distinguish the typed expression from the result.我的观点是,如果您在 Immediate Window 中,问号 ('?') 是不必要的,它用于区分键入的表达式和结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM