实验一---2018-10-08

添加参数的方法:解决方案资源管理器中文件名右击->属性->调试->命令行参数

//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();
        }
    }
}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,872评论 19 139
  • 国家电网公司企业标准(Q/GDW)- 面向对象的用电信息数据交换协议 - 报批稿:20170802 前言: 排版 ...
    庭说阅读 13,944评论 6 13
  • 路9:23耶稣又对众人说:“若有人要跟从我,就当舍己,天天背起他的十字架来跟从我。 9:24因为,凡要救自己生命(...
    宁宁2018阅读 1,738评论 0 0
  • 这个世界上我最佩服的人,就是不惧流言可以坚持自我的人。面对流言很少人能做到不畏惧,不抱怨。流言常常会令我们深陷被动...
    草莓灌汤包阅读 1,950评论 0 0

友情链接更多精彩内容