博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#练习4
阅读量:7069 次
发布时间:2019-06-28

本文共 3873 字,大约阅读时间需要 12 分钟。

//错误的程序 using System;class Test{    unsafe static void WriteLocations(byte[]arr)    {        fixed(byte*p_arr=arr)        {            byte* p_elem = p_arr;            for(int i=0;i

 

static void Main(){F();G();{H();I();}}static void Main(String[]args){if(args.Length==0)goto done;Console.WriteLine(args.Length);done:Console.WriteLine("Done");}static void Main(){const float pi=3.14;const int r=123;Console.WriteLine(pi*i*i);}static void Main(){int a;int b=2,c=3;a=1;Console.WriteLine(a+b+c);}static int F

 

using System;class MyClass{    public MyClass()    {        Console.WriteLine("Constructor");    }    public MyClass(int value)    {        MyField = value;        Console.WriteLine("Destructor");    }    ~MyClass()    {        Console.WriteLine("Destructor");    }    public const int MyConst = 12;    public int MyField = 34;    public void MyMethod()    {        Console.WriteLine("MyClass.MyMethod");    }    public int Myproperty()    {        get{            return MyField;        }        set{            MyField=value;        }    }    public int this[int index]{        get        {            return 0;        }        set        {            Console.WriteLine("this[{0}]{1}", index, value);        }    }    public event EventHandler MyEvent;    public static MyClass operator+(MyClass a,MyClass b)    {        return new MyClass(a.MyField + b.MyField);    }    internal class MyNestedClass { }   }class Constans{    public const int A = 1;    public const int B = A + 1;}class Test{    static void Main()    {        Console.WriteLine("{0},{1}", Constans.A, Constans.B);    }}//Fieldsclass Color{    internal ushort redpart;    internal ushort bluepart;    internal ushort greenpart;    public Color(ushort red,ushort blue,ushort green)    {        redpart = red;        bluepart = blue;        greenpart = green;    }}class Color{    public static Color Red = new Color(0XFF, 0, 0);    public static Color Blue = new Color(0, 0XFF, 0);    public static Color Green = new Color(0, 0, 0XFF);    public static Color While = new Color(0, 0, 0);}
using System;class Point{    public double x, y;    public Point(){    this.x=0;    this.y=0;}public Point(double x,double y)    {        this.x = x;        this.y = y;    }    public static double Distance(Point a,Point b){    double xdiff = a.x - b.x;    double ydiff = a.y - b.y;    return Math.Sqrt(xdiff * xdiff + ydiff * ydiff);}    public override string ToString()    {        return string.Format("{0},{1}",x,y);    }}class Test{    static void Main()    {        Point a = new Point();        Point b = new Point(3, 4);        double d = Point.Distance(a, b);        Console.WriteLine("Distance from {0} to {1} is {2}", a, b, d);    }}

 

 

using System;class Point{    public double x, y;    public Point(double x, double y) {        this.x = x;        this.y = y;     }    ~Point()    {        Console.WriteLine("Destructed {0}", this);    }    public override string ToString()    {        return string.Format("{0},{1}",x,y);    }}

 

using System;class Test{    static void Main()    {        Type type = typedef(Class1);        object[] arr = type.GetCustomAttributes(typeof(HelpAttribute));        if (arr.Length == 0)            Console.WriteLine("Class1 has no Help attribute.");        else        {            HelpAttribute ha = (HelpAttribute)arr[0];            Console.WriteLine("Ur1={0},Topic={1}", ha.Ur1, ha.Topic);        }    }}

 

using System;class Test{    static void Main()    {        Type type = typedef(Class1);        object[] arr = type.GetCustomAttributes(typeof(HelpAttribute));        if (arr.Length == 0)            Console.WriteLine("Class1 has no Help attribute.");        else        {            HelpAttribute ha = (HelpAttribute)arr[0];            Console.WriteLine("Ur1={0},Topic={1}", ha.Ur1, ha.Topic);        }    }}

 

转载于:https://www.cnblogs.com/zhangyongjian/p/3580145.html

你可能感兴趣的文章
mysql性能优化配置
查看>>
JavaScript继承方式详解
查看>>
解决win7旗舰版无法打开微软论坛
查看>>
烂泥:高负载均衡学习haproxy之安装与配置
查看>>
路由方式通过Iptables解决内网绑定的公网IP问题
查看>>
Ubuntu配置DNS
查看>>
我的友情链接
查看>>
我的碎碎念
查看>>
pymysql添加更新数据没效果
查看>>
TuShare -财经数据接口包
查看>>
数据之加密与解密
查看>>
冷门java程序员的理念
查看>>
JavaScript实现X秒后自动跳转
查看>>
extjs formPanel里的元素居中显示
查看>>
PHP系列(十)GD库
查看>>
android笔记3-文件读取
查看>>
扫描仪和数码相机TWAIN控件VintaSoftTwain.NET Library下载
查看>>
友元关系与继承
查看>>
关于ffmpeg的error返回值
查看>>
CentOS装完后没有网卡配置文件ifcfg-eth0的解决方法
查看>>