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);
}
}
}
随机推荐
- NOIP模拟72
T1 出了个大阴间题 解题思路 看了看数据,大概是个状压 DP,但是感觉记忆化搜索比较好写一点(然而并不是这样递归比迭代常熟大了许多..) 不难判断出来 b 的数值与合并的顺序无关于是我们可以预先处理 ...
- 数据库MHA原理
一.数据库的高可用MHA (1):详细的步骤 1.master mysql宕机了,MHA manager :无法连接master 2.MHA在S1 S2找一个延迟最小的slave,确定为未来的mast ...
- 将Oracle数据库数据每天备份恢复一次数据到另一台服务器上两份数据
1.创建用户,授权,创建测试数据 创建用户 CREATE USER test identified by 123; 授权 grant dba to test; 创建测试数据 create table ...
- 前段--->js
一,java script的引入方式 1,直接在script里书写你的代码 <script> alert("hbflfb")</script> 2,引入额外 ...
- 洛谷5038 [SCOI2012]奇怪的游戏(二分+网络流+判断奇偶)
寒假的时候就听过这个题.但是一直没有写. qwq 首先,我们发现题目中的图是个网格图,然后每次可以将相邻两个格子加一. 很容易就想到是黑白染色.那么每次操作,就相当于同时操作一个白点,一个黑点. 我们 ...
- CentOS 压缩解压
目录 命令 tar gzip.gunzip bzip2.bunzip2 zip.unzip 命令组合 打包:将多个文件合成一个总的文件,这个总的文件通常称为"归档". 压缩:将一个 ...
- Linux信号处理编程
01. 学习目标 了解信号中的基本概念 熟练使用信号相关的函数 了解内核中的阻塞信号集和未决信号集作用 熟悉信号集操作相关函数 熟练使用信号捕捉函数signal 熟练使用信号捕捉函数sigaction ...
- Kruskal重构树-进阶
例题一:区间最小生成树(NKOJ P8439) 简要题意: 一个n个点m条边的无向图,点编号1到n,边编号1到m.边有边权. 有q次操作,操作分两种: 1.k x y z:修改第k条边,使其连接的两点 ...
- Python环境配置详细步骤以及第一个程序
打开python官网:https://www.python.org/ 在官网找与自己电脑系统匹配的版本路径 这里以python3.7.2版本为例: 下载完成后,使用管理员身份进行安装: 打开命令提 ...
- 【linux】修改ip后hadoop只有四个节点的问题
学校的机房,每重启一次就会将虚拟机的某些配置还原到部署到学生机时候的状态(例如.etc/hosts文件中ip与主机名的映射),这个时候与我们前面所部署的hadoop就会产生IP不对应的状态,导致了ha ...