直接从 cmd 或 Visual Studio 运行 vb.net 代码 [英] Run vb.net code directly from cmd or Visual Studio

查看:62
本文介绍了直接从 cmd 或 Visual Studio 运行 vb.net 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 vb.net 编写代码,我需要直接运行代码,就像在 java 中发生的那样:在 cmd 中我可以运行类文件.vb.net 是否有类似的可能性,最好直接来自 Visual Studio 中心?

I'm starting to code with vb.net and i need to run the code directly, like it happens with java: in the cmd i can run the class files. Is there any similar possibility with vb.net, preferably directly from the visual studio hub?

谢谢!

推荐答案

您可以使用 立即窗口.它提供了许多不同的方式来与您的代码进行交互.要使用它,请从 Visual Studio 以调试模式启动应用程序,然后按 CTRL + ALT + I.

You can use the Immediate Window for that. It offers many different ways to interact with your code. To use it, start your application in debug mode from Visual Studio and press CTRL + ALT + I.

要执行共享方法,您可以在立即窗口中键入:

To execute a shared method you can type in the Immediate Window:

className.methodName()

(example)
MainFunctions.DoStuff()
DoMoreStuff()

  • 其中 className 是可选的,如果您当前已经在课程中(例如,如果您在课程中遇到了断点).
    • Where className is optional if you're currently already inside the class (for example if you've hit a breakpoint in it).
    • 如果你想执行一个实例(非共享)方法,你可以使用上面的方法(没有className,但你必须当前在类中通过点击断点,例如),或者您创建类的新实例并执行该方法:

      If you want to execute an instance (non-shared) method you can either use the method above (without className, but you must currently be inside the class by hitting a breakpoint, for example), or you create a new instance of the class and execute the method:

      Public Class MiscFunctions
          Public Sub PrintHelloWorld()
              Debug.WriteLine("Hello World!")
          End Sub
      End Class
      


      (Immediate Window)
      New MiscFunctions().PrintHelloWorld()
      Hello World!
      
      Dim m As New MiscFunctions
      m.PrintHelloWorld()
      Hello World!
      

      您还可以通过键入以下内容来打印变量的值或函数的返回值:

      You can also print the value of a variable or the return value of a function by typing:

      ? variableOrFunctionNameHere
      
      (example)
      ? ImageCount
      4
      

      执行方法的相同规则也适用于评估函数:

      The same rules for executing methods applies to evaluating functions too:

      Public Class MiscFunctions
          Public Shared Function IsEven(ByVal Num As Integer) As Boolean
              Return Num Mod 2 = 0
          End Function
      
          Public Function Sum(ByVal a As Integer, ByVal b As Integer) As Integer 'Non-shared method.
              Return a + b
          End Function
      End Class
      


      (Immediate Window)
      ? MiscFunctions.IsEven(3)
      False
      ? MiscFunctions.IsEven(8)
      True
      ? New MiscFunctions().Sum(3, 9)
      12
      

      您还可以动态评估表达式:

      You can also dynamically evaluate expressions:

      ? ImageCount + 1 = 5 'Here, ImageCount is 4
      True
      ? 2 * 4
      8
      

      这篇关于直接从 cmd 或 Visual Studio 运行 vb.net 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆