当前位置: 首页 > news >正文

C#练习4

//错误的程序
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<arr.Length;i++) byte value=*p_elem; string addr=int.Format((int)p_elem,"x"); Console.WriteLine("arr[{0}]at0x{1}is{2}",i,addr,value); p_elem++; } } } static void Main() { byte[]Array=new byte[]{1,2,3,4,5}; WriteLocations(arr); }

 

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

//Fields
class 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

相关文章:

  • python 基础语法 - 函数(一)
  • Mysql在sql中截取时间类型字段的年月日
  • 小议C#接口的隐式与显示实现
  • 【node】搭建自己的博客开坑(一)——项目的构思与设计——(后端部分)
  • linux内核管理--之定制一个属于自己的小型系统
  • 十二月技术考核:Windows系统故障排查
  • Android 之 内存管理
  • 尝试使用Open Live Writer写博客
  • 敏捷 扑克上的时间估算(转)
  • 码云新增GVP(最有价值)项目(10、11月合辑) | 码云周刊第 90 期
  • 您应该了解的 Windows Azure 网站在线工具
  • 多维数组拍平一层
  • Go语言的接口
  • IE9、 Firefox、Safari, Chrome的CSS3圆角属性
  • 2018年终总结_四年计算机科班学习经验分享+半年工作感悟
  • ➹使用webpack配置多页面应用(MPA)
  • Docker 1.12实践:Docker Service、Stack与分布式应用捆绑包
  • FastReport在线报表设计器工作原理
  • JavaScript函数式编程(一)
  • JAVA多线程机制解析-volatilesynchronized
  • KMP算法及优化
  • leetcode讲解--894. All Possible Full Binary Trees
  • mysql 数据库四种事务隔离级别
  • Netty源码解析1-Buffer
  • React-flux杂记
  • React-生命周期杂记
  • SQLServer之索引简介
  • 理解 C# 泛型接口中的协变与逆变(抗变)
  • 手写一个CommonJS打包工具(一)
  • 微服务框架lagom
  • 我看到的前端
  • 新书推荐|Windows黑客编程技术详解
  • 职业生涯 一个六年开发经验的女程序员的心声。
  • LIGO、Virgo第三轮探测告捷,同时探测到一对黑洞合并产生的引力波事件 ...
  • 长三角G60科创走廊智能驾驶产业联盟揭牌成立,近80家企业助力智能驾驶行业发展 ...
  • ​ 全球云科技基础设施:亚马逊云科技的海外服务器网络如何演进
  • (06)金属布线——为半导体注入生命的连接
  • (C++17) std算法之执行策略 execution
  • (pojstep1.1.1)poj 1298(直叙式模拟)
  • (二)Linux——Linux常用指令
  • (附源码)springboot宠物管理系统 毕业设计 121654
  • (附源码)springboot金融新闻信息服务系统 毕业设计651450
  • (十八)三元表达式和列表解析
  • (四)Tiki-taka算法(TTA)求解无人机三维路径规划研究(MATLAB)
  • (原)本想说脏话,奈何已放下
  • (转载)VS2010/MFC编程入门之三十四(菜单:VS2010菜单资源详解)
  • *Django中的Ajax 纯js的书写样式1
  • .NET Core/Framework 创建委托以大幅度提高反射调用的性能
  • .Net IE10 _doPostBack 未定义
  • .net refrector
  • .Net 高效开发之不可错过的实用工具
  • .net 托管代码与非托管代码
  • .Net 知识杂记
  • .NET 中使用 TaskCompletionSource 作为线程同步互斥或异步操作的事件
  • .NET中的Event与Delegates,从Publisher到Subscriber的衔接!