一个简单的C#命令行参数程序

新建一个c#控制台程序,命名为ConsoleApplication1

程序主体如下

class Program
 {
  static void Main(string[] args)
  {
   System.Console.WriteLine("parameter count = {0}", args.Length);

   for (int i = 0; i < args.Length; i++)
   {
    System.Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
   }
   Console.ReadLine();
  }
 }

 

运行如下图所示,F:\C#Workspace\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1 为程序exe所在的路径 a b c 为程序的运行参数,参数间用空格隔开(默认)参数与路径也用空格隔开。  

2018-6-8 11:30:37(管理员) 抢沙发(1) .net
阅读全文
1/1, 1«1»
系统公告

文章分类
搜索
最新评论
站点数据
栏目总数: 2 个
页面数量: 1 篇
评论数量: 1 条
标签数量: 5 个
合作伙伴: 3 位
附件数量: 0 个
XML
<?xml version="1.0" encoding="utf-8"?>
<ui>
	<config>
		<path><![CDATA[/]]></path>
		<system><![CDATA[isRoc]]></system>
		<version><![CDATA[1.3.13 SP1]]></version>
		<fullVersion><![CDATA[isRoc v1.3.13 SP1]]></fullVersion>
		<powered><![CDATA[Powered by <a href="http://www.isroc.com/" rel="external"><strong>isRoc</strong></a> <em>v1.3.13 SP1</em>]]></powered>
	</config>
	<setting>
		<theme><![CDATA[Amarketer-blue]]></theme>
		<language><![CDATA[]]></language>
		<name><![CDATA[我的网站]]></name>
		<url><![CDATA[http://zhenggc.cn/]]></url>
		<intro><![CDATA[我的个人网站]]></intro>
		<keywords><![CDATA[]]></keywords>
		<icp><![CDATA[备案号]]></icp>
		<affiche><![CDATA[<p>
	无</p>]]></affiche>
	</setting>
	<navigations>
		<item>
			<link><![CDATA[/]]></link>
			<name><![CDATA[主页]]></name>
			<intro><![CDATA[我的网站]]></intro>
			<target><![CDATA[_self]]></target>
			<current>False</current>
		</item>
		<item>
			<link><![CDATA[/category/1.aspx]]></link>
			<name><![CDATA[.net]]></name>
			<intro><![CDATA[.net技术]]></intro>
			<target><![CDATA[]]></target>
			<current>False</current>
		</item>
	</navigations>
	<categorys>
		<item>
			<link><![CDATA[/category/1.aspx]]></link>
			<id>1</id>
			<name><![CDATA[.net]]></name>
			<intro><![CDATA[.net技术]]></intro>
			<local><![CDATA[1]]></local>
			<postCount>1</postCount>
		</item>
		<item>
			<link><![CDATA[/category/2.aspx]]></link>
			<id>2</id>
			<name><![CDATA[SQL]]></name>
			<intro><![CDATA[Sql技术]]></intro>
			<local><![CDATA[2]]></local>
			<postCount>0</postCount>
		</item>
	</categorys>
	<randomArticles>
		<item>
			<link><![CDATA[/article/1.aspx]]></link>
			<id>1</id>
			<title><![CDATA[一个简单的C#命令行参数程序]]></title>
			<tags><![CDATA[]]></tags>
			<local><![CDATA[1]]></local>
			<author><![CDATA[管理员]]></author>
			<postCount>1</postCount>
			<reader>176</reader>
			<vote>0</vote>
			<fine>False</fine>
			<publish>2018-6-8 11:30:37</publish>
			<category>
				<link><![CDATA[/category/1.aspx]]></link>
				<id>1</id>
				<local><![CDATA[1]]></local>
				<name><![CDATA[.net]]></name>
				<intro><![CDATA[.net技术]]></intro>
				<postCount>1</postCount>
			</category>
		</item>
	</randomArticles>
	<hotArticles>
		<item>
			<link><![CDATA[/article/1.aspx]]></link>
			<id>1</id>
			<title><![CDATA[一个简单的C#命令行参数程序]]></title>
			<tags><![CDATA[]]></tags>
			<local><![CDATA[1]]></local>
			<author><![CDATA[管理员]]></author>
			<postCount>1</postCount>
			<reader>176</reader>
			<vote>0</vote>
			<fine>False</fine>
			<publish>2018-6-8 11:30:37</publish>
			<category>
				<link><![CDATA[/category/1.aspx]]></link>
				<id>1</id>
				<local><![CDATA[1]]></local>
				<name><![CDATA[.net]]></name>
				<intro><![CDATA[.net技术]]></intro>
				<postCount>1</postCount>
			</category>
		</item>
	</hotArticles>
	<fineArticles>
		<item>
			<link><![CDATA[/article/1.aspx]]></link>
			<id>1</id>
			<title><![CDATA[一个简单的C#命令行参数程序]]></title>
			<tags><![CDATA[]]></tags>
			<local><![CDATA[1]]></local>
			<author><![CDATA[管理员]]></author>
			<postCount>1</postCount>
			<reader>176</reader>
			<vote>0</vote>
			<fine>False</fine>
			<publish>2018-6-8 11:30:37</publish>
			<category>
				<link><![CDATA[/category/1.aspx]]></link>
				<id>1</id>
				<local><![CDATA[1]]></local>
				<name><![CDATA[.net]]></name>
				<intro><![CDATA[.net技术]]></intro>
				<postCount>1</postCount>
			</category>
		</item>
	</fineArticles>
	<newComments>
	</newComments>
	<pages>
	</pages>
	<tags>
		<item>
			<link><![CDATA[/tag/net.aspx]]></link>
			<id>1</id>
			<key><![CDATA[net]]></key>
			<postCount>0</postCount>
		</item>
		<item>
			<link><![CDATA[/tag/SQL.aspx]]></link>
			<id>2</id>
			<key><![CDATA[SQL]]></key>
			<postCount>0</postCount>
		</item>
		<item>
			<link><![CDATA[/tag/QQ.aspx]]></link>
			<id>3</id>
			<key><![CDATA[QQ]]></key>
			<postCount>0</postCount>
		</item>
		<item>
			<link><![CDATA[/tag/PowerBuilder.aspx]]></link>
			<id>4</id>
			<key><![CDATA[PowerBuilder]]></key>
			<postCount>0</postCount>
		</item>
		<item>
			<link><![CDATA[/tag/%e6%95%b0%e6%8d%ae%e5%ba%93.aspx]]></link>
			<id>5</id>
			<key><![CDATA[数据库]]></key>
			<postCount>0</postCount>
		</item>
	</tags>
	<fellows>
		<item>
			<id>1</id>
			<name><![CDATA[51aspx]]></name>
			<url><![CDATA[http://www.51aspx.com]]></url>
			<logo><![CDATA[]]></logo>
			<explain><![CDATA[]]></explain>
			<style><![CDATA[]]></style>
		</item>
		<item>
			<id>2</id>
			<name><![CDATA[zhenggc.cc]]></name>
			<url><![CDATA[http://zhenggc.cc]]></url>
			<logo><![CDATA[]]></logo>
			<explain><![CDATA[zhenggc.cc]]></explain>
			<style><![CDATA[]]></style>
		</item>
		<item>
			<id>3</id>
			<name><![CDATA[zhenggc.com]]></name>
			<url><![CDATA[http://zhenggc.com]]></url>
			<logo><![CDATA[]]></logo>
			<explain><![CDATA[zhenggc.com]]></explain>
			<style><![CDATA[]]></style>
		</item>
	</fellows>
	<myTag>
	</myTag>
	<this>
		<title><![CDATA[我的网站 - 我的个人网站]]></title>
		<tagName><![CDATA[]]></tagName>
		<searchKey><![CDATA[]]></searchKey>
		<categoryName><![CDATA[]]></categoryName>
		<articles>
			<pages><![CDATA[<div class="sysPages"><span>1/1, 1</span><a href="/?cid=0&tag=&key=&page=1">«</a><a href="/?cid=0&tag=&key=&page=1">‹</a><b>1</b><a href="/?cid=0&tag=&key=&page=1">›</a><a href="/?cid=0&tag=&key=&page=1">»</a></div>]]></pages>
			<item>
				<link><![CDATA[/article/1.aspx]]></link>
				<id>1</id>
				<title><![CDATA[一个简单的C#命令行参数程序]]></title>
				<local><![CDATA[1]]></local>
				<tags><![CDATA[]]></tags>
				<explain><![CDATA[<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun;">
	新建一个c#控制台程序,命名为ConsoleApplication1</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun;">
	程序主体如下</p>
<pre class="csharp" name="code">
class Program
 {
  static void Main(string[] args)
  {
   System.Console.WriteLine(&quot;parameter count = {0}&quot;, args.Length);

   for (int i = 0; i &lt; args.Length; i++)
   {
    System.Console.WriteLine(&quot;Arg[{0}] = [{1}]&quot;, i, args[i]);
   }
   Console.ReadLine();
  }
 }</pre>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun;">
	&nbsp;</p>

<span style="color: rgb(79, 79, 79); font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun; font-size: 16px; line-height: 26px; text-align: justify;">运行如下图所示,F:\C#Workspace\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1 为程序exe所在的路径 a b c 为程序的</span><span style="color: rgb(79, 79, 79); font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun; font-size: 16px; line-height: 26px; text-align: justify;">运行参数,参数间用空格隔开(默认)参数与路径也用空格隔开。</span> 
	&nbsp;</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun;">
	<img alt="" src="https://img-blog.csdn.net/20150616011238204" style="box-sizing: border-box; outline: 0px; margin: 0px; max-width: 100%; word-break: break-all; cursor: zoom-in;" /></p>]]></explain>
				<content><![CDATA[<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun;">
	新建一个c#控制台程序,命名为ConsoleApplication1</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun;">
	程序主体如下</p>
<pre class="csharp" name="code">
class Program
 {
  static void Main(string[] args)
  {
   System.Console.WriteLine(&quot;parameter count = {0}&quot;, args.Length);

   for (int i = 0; i &lt; args.Length; i++)
   {
    System.Console.WriteLine(&quot;Arg[{0}] = [{1}]&quot;, i, args[i]);
   }
   Console.ReadLine();
  }
 }</pre>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun;">
	&nbsp;</p>

<span style="color: rgb(79, 79, 79); font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun; font-size: 16px; line-height: 26px; text-align: justify;">运行如下图所示,F:\C#Workspace\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1 为程序exe所在的路径 a b c 为程序的</span><span style="color: rgb(79, 79, 79); font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun; font-size: 16px; line-height: 26px; text-align: justify;">运行参数,参数间用空格隔开(默认)参数与路径也用空格隔开。</span> 
	&nbsp;</p>
<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: 'PingFang SC', 'Microsoft YaHei', SimHei, Arial, SimSun;">
	<img alt="" src="https://img-blog.csdn.net/20150616011238204" style="box-sizing: border-box; outline: 0px; margin: 0px; max-width: 100%; word-break: break-all; cursor: zoom-in;" /></p>]]></content>
				<publish>2018-6-8 11:30:37</publish>
				<author><![CDATA[管理员]]></author>
				<postCount>1</postCount>
				<reader>176</reader>
				<vote>0</vote>
				<fine>False</fine>
				<category>
					<link><![CDATA[/category/1.aspx]]></link>
					<id>1</id>
					<local><![CDATA[1]]></local>
					<name><![CDATA[.net]]></name>
					<intro><![CDATA[.net技术]]></intro>
					<postCount>1</postCount>
				</category>
			</item>
		</articles>
	</this>
	<expand>
	</expand>
</ui>
Timer:0.4499s