ConsoleApplicationBase.CommandLineArgs 属性     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个集合,该集合包含当前应用程序的字符串形式的命令行参数。
public:
 property System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ CommandLineArgs { System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ get(); };public System.Collections.ObjectModel.ReadOnlyCollection<string> CommandLineArgs { get; }member this.CommandLineArgs : System.Collections.ObjectModel.ReadOnlyCollection<string>Public ReadOnly Property CommandLineArgs As ReadOnlyCollection(Of String)属性值
              String 类型的 ReadOnlyCollection<T>,包含当前应用程序的命令行参数,参数形式为字符串。
示例
此示例使用 My.Application.CommandLineArgs 属性检查应用程序的命令行参数。 如果找到以 /input=开头的参数,则显示该参数的其余部分。
Private Sub ParseCommandLineArgs()
    Dim inputArgument As String = "/input="
    Dim inputName As String = ""
    For Each s As String In My.Application.CommandLineArgs
        If s.ToLower.StartsWith(inputArgument) Then
            inputName = s.Remove(0, inputArgument.Length)
        End If
    Next
    If inputName = "" Then
        MsgBox("No input name")
    Else
        MsgBox("Input name: " & inputName)
    End If
End Sub
注解
属性 My.Application.CommandLineArgs 为未部署 ClickOnce 的应用程序提供对当前应用程序的命令行参数的只读访问权限。
对于单实例应用程序, My.Application.CommandLineArgs 属性返回应用程序的第一个实例的命令行参数。 若要访问用于后续尝试启动单实例应用程序的参数,必须处理 StartupNextInstance 事件并检查 CommandLine 参数的 StartupEventArgs 属性。
注意
属性 My.Application.CommandLineArgs 仅返回命令行参数。 这与 属性的行为 CommandLine 不同,该属性除了参数外还返回应用程序名称。
注意
在 ClickOnce 部署的应用程序中,使用 ActivationUri 对象的 属性 My.Application.Deployment 获取命令行参数。 有关详细信息,请参阅 Deployment。
下表列出了涉及 My.Application.CommandLineArgs 属性的任务示例。
| 功能 | 查看 | 
|---|---|
| 检查后续尝试启动单实例应用程序的命令行参数 | StartupNextInstance | 
可用性(按项目类型)
| 项目类型 | 可用 | 
|---|---|
| Windows 应用程序 | 是 | 
| 类库 | 否 | 
| 控制台应用程序 | 是 | 
| Windows 控件库 | 否 | 
| Web 控件库 | 否 | 
| Windows 服务 | 是 | 
| 网站 | 否 |