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

后端 未结 8 1726
自闭症患者
自闭症患者 2021-02-04 06:35

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

My.Application.Info.DirectoryPath

My.Computer.Clipboard

My.Com         


        
相关标签:
8条回答
  • 2021-02-04 06:42
    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)
    
    0 讨论(0)
  • 2021-02-04 06:45
    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.

    0 讨论(0)
  • 2021-02-04 06:49

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

    System.Reflection.Assembly.GetExecutingAssembly().Location;
    //gets file path with file name
    
    System.Windows.Clipboard;
    
    System.Media.SystemSounds.[Sound].Play();
    
    System.Windows.Application.Current.Shutdown();
    
    0 讨论(0)
  • 2021-02-04 06:50

    Application.ExecutablePath

    System.Windows.Forms.Clipboard

    System.Media.*

    Application.Exit

    0 讨论(0)
  • 2021-02-04 06:53

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

    Path.GetDirectoryName(
        new AssemblyInfo(
            Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).Location);
    
    0 讨论(0)
  • 2021-02-04 06:56

    The following

    using System.IO;
    Directory.GetCurrentDirectory()
    
    0 讨论(0)
提交回复
热议问题