什么是最好的C#(CSHARP)当量以下VB(VB.NET,VisualBasic中)声明:转换VB到C# - My.Application.Info.DirectoryPath
My.Application.Info.DirectoryPath
My.Computer.Clipboard
My.Computer.Audio.PlaySystemSound()
My.Application.Shutdown()
什么是最好的C#(CSHARP)当量以下VB(VB.NET,VisualBasic中)声明:转换VB到C# - My.Application.Info.DirectoryPath
My.Application.Info.DirectoryPath
My.Computer.Clipboard
My.Computer.Audio.PlaySystemSound()
My.Application.Shutdown()
Application.ExecutablePath
System.Windows.Forms.Clipboard
System.Media。*
Application.Exit
这可能不是什么您正在寻找,但为了防止您想要使用快捷方式,如果添加对Microsoft.VisualBasic程序集的引用,则可以使用VB程序员通过命名空间MyServices访问的漂亮工具。
好捷径,但是,我一直在寻找普遍的选择。我相信这会帮助别人。 – 2009-08-11 13:12:53
如果要转换一个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();
我觉得你海RCH就是这句话:
Application.StartupPath;
//Get file path without file name.
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)
这些My.Application.Info.DirectoryPath AppDomain.CurrentDomain.BaseDirectory为我提供了不同的答案。正确的答案似乎是GetFilePath(System.Reflection.Assembly.GetExecutingAssembly.Location) – user2728841 2017-12-27 14:52:25
从反编译Microsoft.VisualBasic.dll中,调用My.Application.Info.DirectoryPath
当被执行的实际代码是:
Path.GetDirectoryName(
new AssemblyInfo(
Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).Location);
System.IO.Directory.GetParent(Application.ExecutablePath)
是完全一样的:
My.Application.Info.DirectoryPath
如果你只做:
Application.ExecutablePath
你会得到执行文件追加到路径,这可能根本没有用。
根据[Scuzzlebutt](http://stackoverflow.com/a/36102900/1677912),这是不正确的。 GetParent方法返回一个DirectoryInfo对象,而不是路径(字符串)。您需要使用FullName属性来实际获取路径。而不是`System.IO.Directory.GetParent(Application.ExecutablePath)`,使用`System.IO.Directory.GetParent(Application.ExecutablePath).FullName`。 – Mogsdad 2016-04-07 21:11:52
这些对于Windows Forms应用程序来说可能是正确的 – 2009-08-11 13:20:41