class1.cs
来自「C#开发教程 由浅入深 配有实例 是初学者的好帮手」· CS 代码 · 共 41 行
CS
41 行
using System;
namespace UnsafeStruct
{
public struct Insect
{
private int id;
private decimal price;
public Insect(int id, decimal price)
{
this.id = id;
this.price = price;
}
override public string ToString()
{
return String.Format("{0}: {1}", id, price);
}
unsafe public static void Swap(Insect* pi, Insect* pj)
{
Insect tmp = *pi;
*pi = *pj;
*pj = tmp;
}
}
class UnsafeStructApp
{
[STAThread]
static void Main(string[] args)
{
Insect i = new Insect(123, 45.67m);
Insect j = new Insect(890, 98.76m);
Console.WriteLine("Before Swap:\ti = {0}, j = {1}", i, j);
unsafe { Insect.Swap(&i, &j); }
Console.WriteLine("After Swap:\ti = {0}, j = {1}", i, j);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?