如何获取命令行参数的类型 [英] How to get the type of command line arguments

查看:70
本文介绍了如何获取命令行参数的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将命令提示符中的参数传递给表单,我想知道我传递的参数的类型,如何在vb.net中为其编写代码



我尝试过:



i试用此代码



如果Environment.GetCommandLineargs(1).GetType

\\ i必须检查此参数是否为小数

解决方案

参数始终是一个字符串。如果要查看该字符串是否可以转换为小数,请使用十进制.TryParse [ ^ ]


当你获取命令行参数时,它们总是字符串:它们是用户在命令行上输入的用于执行应用程序的内容 - 你可以通过打开命令提示符并键入应用程序的名称,然后输入以空格分隔的参数来提供它们:

 myApp Parameter1参数2,其中包含空格

因此,它们没有整数或十进制意义上的类型。

使用TryParse检查它们:

< pre lang =vb> Dim value As Decimal
如果 十进制 .TryParse(Environment.GetCommandLineargs( 1 ),value)< span class =code-keyword>然后
' 向用户报告问题。
...
返回
结束 如果


i have passed the arguments from the command prompt to the form, i want to know the type of that arguments i passed, how to write code for that in vb.net

What I have tried:

i tried for this code

if Environment.GetCommandLineargs(1).GetType
\\i have to check whether this argument is decimal or not

解决方案

The arguments are always a string. If you want to see if that string can be converted to a decimal then use Decimal.TryParse[^]


When you fetch command line arguments, they are always strings: they are "what the user typed on the command line to execute your application" - and you can supply them that way by opening a command prompt and typing the name of your app followed by space-separated parameters:

myApp Parameter1 "parameter 2 with spaces in"

As such, they don't have a type in the sense of "integer" or "decimal".
Use TryParse to check them:

Dim value As Decimal
If Not Decimal.TryParse(Environment.GetCommandLineargs(1), value) Then
	' Report problem to user.
        ...
	Return
End If


这篇关于如何获取命令行参数的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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