将 VB 转换为 C# - My.Application.Info.DirectoryPath

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1174903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 10:02:04  来源:igfitidea点击:

Convert VB to C# - My.Application.Info.DirectoryPath

c#vb.net

提问by Aaron Hoffman

What are the best C# (csharp) equivalents for the following VB (VB.NET, VisualBasic) statements:

以下 VB (VB.NET, VisualBasic) 语句的最佳 C# (csharp) 等效项是什么:

My.Application.Info.DirectoryPath

My.Computer.Clipboard

My.Computer.Audio.PlaySystemSound()

My.Application.Shutdown()

采纳答案by TheCodeMonk

Application.ExecutablePath

应用程序.可执行路径

System.Windows.Forms.Clipboard

系统.Windows.Forms.剪贴板

System.Media.*

系统.媒体.*

Application.Exit

申请.退出

回答by Mike Dinescu

This may not be exactly what you're looking for, but just in case you want to take a shortcut, if you add a reference to the Microsoft.VisualBasic assembly, you can use the nifty tools VB programmers have access via the MyServicesnamespace.

这可能不是您正在寻找的,但万一您想走捷径,如果您添加对 Microsoft.VisualBasic 程序集的引用,您可以使用 VB 程序员可以通过MyServices命名空间访问的漂亮工具。

回答by Aaron Hoffman

If you are converting a WPF application, you can use the following:

如果要转换 WPF 应用程序,可以使用以下内容:

System.Reflection.Assembly.GetExecutingAssembly().Location;
//gets file path with file name

System.Windows.Clipboard;

System.Media.SystemSounds.[Sound].Play();

System.Windows.Application.Current.Shutdown();

回答by Shiveta

I think that you search is this sentence:

我想你搜索的是这句话:

Application.StartupPath;
//Get file path without file name.

回答by Srinidhi

My.Application.Info.DirectoryPath
  AppDomain.CurrentDomain.BaseDirectory

My.Computer.Clipboard
  System.Windows.Clipboard //(WPF)
  System.Windows.Forms.Clipboard //(WinForms)

My.Computer.Audio.PlaySystemSound()
  System.Media.SystemSounds.*.Play()

My.Application.Shutdown()
  System.Windows.Forms.Application.Exit() //(WinForms)
  or
  System.Windows.Application.Current.Shutdown()  //(WPF)
  or
  System.Environment.Exit(ExitCode)  //(Both WinForms & WPF)

回答by jam40jeff

From decompiling Microsoft.VisualBasic.dll, the actual code that gets executed when calling My.Application.Info.DirectoryPathis:

通过反编译 Microsoft.VisualBasic.dll,调用时实际执行的代码My.Application.Info.DirectoryPath是:

Path.GetDirectoryName(
    new AssemblyInfo(
        Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).Location);

回答by Chookoos

System.IO.Directory.GetParent(Application.ExecutablePath) 

is exactly the same as:

完全相同:

My.Application.Info.DirectoryPath

If you only do:

如果你只做:

Application.ExecutablePath

You will get the executing file appended to the path, which may not be useful at all.

您将获得附加到路径的执行文件,这可能根本没有用。

回答by M.D.G.

The following

下列

using System.IO;
Directory.GetCurrentDirectory()