添加参数的方法:解决方案资源管理器中文件名右击->属性->调试->命令行参数
//HelloWorld程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello,World!");
Console.ReadKey();
}
}
}
//HelloConse程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloConse
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("请输入你的姓名作为参数");
}
else
{
Console.WriteLine("你好!\n"+args[0]);
}
Console.ReadKey();
}
}
}
//TranceDebug程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TranceDebug
{
class Program
{
static void Main(string[] args)
{
int a = 20;
int b = 5;
int c = 100 / a + b;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
//Point程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Point
{
//声明类point
public class Point
{
//声明字段x和y,表示坐标点(x,y)
public int x,y;
//构造函数
public Point(int x,int y)
{
this.x = x;
this.y = y;
}
//声明方法Distance,计算并返回该对象与对象p的距离
public double Distance(Point p)
{
return Math.Sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}
}
class pointTest
{
static void Main()
{
//创建对象p1
Point p1 = new Point(0,4);
//创建对象p2
Point p2 = new Point(3,0);
//调p1的方法计算它和p2的距离
double dist = p1.Distance(p2);
//输出p1,p2,dist
Console.WriteLine("点p1的坐标为:("+p1.x+","+p1.y+")");
Console.WriteLine("点p2的坐标为:("+p2.x+","+p2.y+")");
Console.WriteLine("两点之间的距离为:"+dist);
Console.ReadKey();
}
}
}
//Main返回值程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Main返回值
{
class Program
{
static void Main(string[] args)
{
//输出参数个数
Console.WriteLine("参数个数 = {0}",args.Length);
//使用for语句输出各参数值
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine("Arg[{0}] = [{1}]",i,args[i]);
}
//使用foreach语句输出各参数值
foreach (string s in args)
{
Console.WriteLine(s);
}
Console.ReadKey();
}
}
}