如何在VS2008中传递命令行参数 [英] How to pass command line arguments in VS2008

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

问题描述

如何使用VS2008将命令行参数值传递给c#中的主要方法

How to pass command line argument values to my main method in c# with VS2008

推荐答案

右键单击项目并选择属性",导航至调试"标签,然后在命令行参数:"框中添加自变量值.请记住,您可能还需要选择工作目录:".
Right click on the project and select "Properties", navigate to the "Debug" tab and add your aragument values in the "Command line arguments:" box. Remember you may also need to select the "Working directory:".


请在 ^ ](*),然后在此处发布任何问题.

(*)有时可以称为Topeka.
Please search on google[^] (*) before posting any questions here.

(*) Could be called Topeka occasionally.


示例执行此操作,以创建记事本文件并以.cs扩展名将其保存并粘贴以下代码中

Example to do this create a notepad file and save it with any name with a .cs extension and paste in the following code

using System;
class Command
{

public static void Main(String[ ] args)
{
string name= args[0].ToString();
Console.WriteLine("Name Entered via Command Line argument is: "+name);
}
}



在此
中使用Visual Studio命令提示符 编译完该文件后(csc filename.cs),然后在您运行exe之后,给您起一个名字,即

FileName Radix,然后按Enter键并查看Magic

命令行参数文件只能像这样运行,如果您尝试在开发环境中运行它,则会提示您出现异常提示
System.IndexOutOfRangeException

一旦找到有用的答案,就对我的答案进行评分

谢谢&问候
基:rose:



use the Visual Studio Command Prompt for this
Once this file is compiled(csc filename.cs) then after u run the exe then give ur name i.e

FileName Radix and then press enter and see the Magic

Command Line argument files can only run like this and if u try to run it in the development environment then it will prompt u an Exception saying
System.IndexOutOfRangeException

Do rate my answer once u find it useful

Thanks & Regards
Radix :rose:


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

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