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);
}
}
}
随机推荐
- mysql从零开始之MySQL 选择数据库
MySQL 选择数据库 在你连接到 MySQL 数据库后,可能有多个可以操作的数据库,所以你需要选择你要操作的数据库. 从命令提示窗口中选择MySQL数据库 在 mysql> 提示窗口中可以很简 ...
- Java秘诀!Java赋值运算符介绍
运算符丰富是 Java 语言的主要特点之一,它提供的运算符数量之多,在高级语言中是少见的. Java 语言中的运算符除了具有优先级之外,还有结合性的特点.当一个表达式中出现多种运算符时,执行的先后顺序 ...
- vue基础-动态样式&表单绑定&vue响应式原理
动态样式 作用:使用声明式变量来控制class和style的值 语法: :class/:style 注意:尽可能不要把动态class和静态class一起使用,原因动态class起作用的时间会比较晚,需 ...
- python在指定一行的下一行插入文本
给定一个程序,程序中有许多函数,比如,funcA,funcB,现在,如何在生成的函数中插入一个logger()语句? 这里用一个solidity程序做例子 pragma solidity ^0.4.0 ...
- PHP文件上传漏洞与一句话木马
靶子代码: 前端效果: 这是个没有任何防护的文件上传代码,同时还热心的附上了上传文件的路径. 我们写好php木马后,什么额外工作也不需要做,直接上传就行了.上传后在浏览器里访问该文件,其就会被执行. ...
- 如何使用远程工具连接Linux服务器
大家好,今天我想和大家分享一下Linux如何连接远程控制工具我们都知道,Linux是著名的开源服务器操作系统,而在运维工程师的实际工作当中,我们不大可能时时刻刻都在服务器本地操作.因此这时,我们要用远 ...
- (三)、Docker常用基础命令
1.Docker 帮助命令 帮助命令: docker version 查看版本 docker info 查询docker详细信息 docker --help 查看命令帮助 2.Docker 镜像命令 ...
- pwn200,一道不完全考察ret2libc的小小pwn题
pwn200 ---XDCTF-2015 每日一pwn,今天又做了一个pwn,那个pwn呢???攻防世界的进阶区里的一道小pwn题,虽然这个题考察的知识不多,rop链也比较好构建,但是还是让我又学到了 ...
- C语言中都有哪些常见的数据结构你都知道几个??
上次在面试时被面试官问到学了哪些数据结构,那时简单答了栈.队列/(ㄒoㄒ)/~~其它就都想不起来了,今天有空整理了一下几种常见的数据结构,原来我们学过的数据结构有这么多~ 首先,先来回顾下C语言中常见 ...
- JVM:Hotspot虚拟机中的对象
在HotSpot虚拟机中,对象在内存中存储的布局可以被分为3个区域:对象头(Header).实例数据(Instance data)和对齐填充(Padding).对象头包括两部分信息,第一部分存储自身的 ...