using System;
public class MyClass
{
public unsafe static void Main()
{
int * buf = stackalloc int [5];
for(int i = 0; i < 5; i++) buf[i] = i; for(int i = 0; i < 5; i++) Console.WriteLine(buf[i]); } } [/csharp]
using System;
public class MyClass
{
public unsafe static void Main()
{
int * buf = stackalloc int [5];
for(int i = 0; i < 5; i++) buf[i] = i; for(int i = 0; i < 5; i++) Console.WriteLine(buf[i]); } } [/csharp]
using System;
public class MyClass
{
public unsafe static void Main()
{
int i;
int [] intArr;
intArr = new int [5];
fixed(int * IntegerPointer = intArr)
{
for(i = 0; i < 5; i++)
IntegerPointer[i] = i;
}
for(i = 0; i < 5; i++)
Console.WriteLine(intArr[i]);
}
}
[/csharp]
Expression Result
sizeof(sbyte) 1
sizeof(byte) 1
sizeof(short) 2
sizeof(ushort) 2
sizeof(int) 4
sizeof(uint) 4
sizeof(long) 8
sizeof(ulong) 8
sizeof(char) 2
sizeof(float) 4
sizeof(double) 8
sizeof(bool) 1
using System;
public struct Point2D {
public int X;
public int Y;
}
public class MyClass {
public unsafe static void Main() {
Point2D MyPoint;
Point2D * PointerToMyPoint;
MyPoint = new Point2D();
PointerToMyPoint = &MyPoint;
PointerToMyPoint->X = 100;
PointerToMyPoint->Y = 200;
Console.WriteLine("({0}, {1})", PointerToMyPoint->X, PointerToMyPoint->Y);
}
}
using System;
public class MyClass
{
public unsafe static void Main()
{
int MyInteger = 123;
int * MyIntegerPointer = &MyInteger;
Console.WriteLine(*MyIntegerPointer);
}
}
using System;
public class MainClass {
static void Main(string[] args) {
unsafe {
int variable = 10;
int* pVariable = &variable;
Console.WriteLine("Value at address is {0}.", *pVariable);
}
}
}
using System;
using System.Collections;
class Class1 {
static void Main(string[] args) {
long lngResult;
long lngValue = 0;
try {
lngResult = 8 / lngValue;
}
catch (Exception objE) {
Console.WriteLine(objE.ToString());
}
}
}