命令行参数未在C#中显示 [英] Command line arguments not being shown in C#

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

问题描述

以下是来自 的代码[ ^ ]。我正在尝试显示命令行参数ABCD,但没有显示





 // Hello3。 cs 
//参数:ABCD
使用System;

公共类Hello3
{
public static void Main(string [] args)
{
Console.WriteLine(Hello,World!) ;
Console.WriteLine(您输入了以下{0}命令行参数:,
args.Length);
for(int i = 0; i< args.Length; i ++)
{
Console.WriteLine({0},args [i]);
}
}
}

解决方案

一切看起来都正确。如果你没有看到参数,我打赌你没有输入任何参数。也许你不知道它是什么;这是我能想到的唯一解释。您的评论论点:A B C D看起来很可疑:是什么让您认为参数是A B C D?



所以,请确保您理解它;请阅读:

http://en.wikipedia.org/wiki/Command-line_argument #Arguments [ ^ ]。



忽略所有这些使用 - ,/或类似的规则。要通过代码显示,它可以是在应用程序集的主可执行模块的文件名后输入的任何字符串。



-SA

Following is code from [^]. I am trying to display command line args A B C D but nothing is
displayed.

// Hello3.cs
// arguments: A B C D
using System;

public class Hello3
{
   public static void Main(string[] args)
   {
      Console.WriteLine("Hello, World!");
      Console.WriteLine("You entered the following {0} command line arguments:",
         args.Length );
      for (int i=0; i < args.Length; i++)
      {
         Console.WriteLine("{0}", args[i]); 
      }
   }
}

解决方案

Everything looks correct. If you don't see the arguments, I bet you did not enter any. Perhaps you don't know what is it; this is the only explanation I can think of. Your comment "arguments: A B C D" looks suspicious: what makes you thinking that the arguments are "A B C D"?

So, make sure you understand it; please read:
http://en.wikipedia.org/wiki/Command-line_argument#Arguments[^].

Ignore all these rules of using -, / or anything like that. To be shown by your code, it could be any string entered after the name of the file of your main executable module of your application assembly.

—SA


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

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