- using System;
- namespace UnsafeTest
- {
- unsafe struct link
- {
- public int x;
- public link* next;
- }
- class Program
- {
- static unsafe void Main(string[] args)
- {
- int val;
- link* head = stackalloc link[sizeof(link)];
- link*q =head;
- for(int i=0;i<=10;i++)
- {
- val = i+100;
- link* temp = stackalloc link[sizeof(link)];
- q->x = val;
- q->next = temp;
- q = temp;
- }
- link* t = head;
- while(t->next!=null)
- {
- Console.WriteLine(t->x );
- t = t->next;
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1101201614402.html
来源: http://www.codesnippet.cn/detail/1101201614402.html