Unsafe clause in C#

Unsafe clause is used to point out the unsafe environments in C#. As we know, there is no pointer in C#,for the pointer is "unsafe", if a pointer points to a  unexpected location in memory, it might cause exception. If we want to use pointers in C#, we have to use them in an "unsafe " environment that CLR knows.
1).Unsafe clause could define a method, property or ctor(unstatic ctor) as unsafe.The unsafe method is from the parameters of method to the end of the method.
for example:


1static unsafe void FastCopy(byte* ps, bype* pd,int count)
2
2)  unsafe clause also could mention a unsafe clause or a clause block.like this :


unsafe 
{
unsafe clause1;
unsafe clause2;

}
However, if you have only one clause , you should also use a pair of brackets.(tested under 2002, - - ~~~OU~so old...)
an complete small test code like this:



using System;
class UnsafeTest
{
//here we could find "unsafe static"=="static unsafe",compile result is the same.
unsafe static void SquarePtrParam(int* p)
{
*p*=*p;
}

[STAThread]
public  static void Main(string[] args)
{
   
int i=5;
   
unsafe     
   
{
     SquarePtrParam(
&i);
   }

   Console.WriteLine(
"i"+i);
}

}
Here ,we could know, When you want to use a pointer(usually the type of the pointed is a  numberic value not a reference value), as a parameter in a unsafe method,you also will use a pointer as an input parameter when you use this unsafe method,so ,the invoke class should also have an unsafe clause block.

Plus: if you want to compile unsafe code under the CLR, you need to mention /unsafe to compiler directly. You can set this property in your project property page (right click the project in solution manager explore, then you will find it at the bottom of the menu.)Then, click the configuration property ,and choose "generation"-- the first subchoice.
You will find the default property of  allowing unsafe check is false .You need to set it to "True".

For further study ,I want to explore the difference between the safe method and the unsafe.That 's need knowledge of IL language. I hope I could explore after getting a book about IL.:)

Note: For my .NET IDE is a Chinese version, I don't know whether words about  the english menu are correct. Sorry~~ 

感谢~~

感谢你们,给了我努力奋斗、认真生活的勇气和力量~~

我会永远和你们在一起:)

Duwamish Beginning

     这几天发现了Duwamish这个有用的东东,非常非常想在毕业前好好的研究一下,自己学的东西太浮躁了,看起来学了很多,而实际上单个拎出什么东西都不行。学计算机的,一定要多研究程序。

    Duwamish 门前一座大山。

自己到底要的是什么(摘自MVM的BLOG)

原贴出处:http://home.wangjianshuo.com/mvm/

想明白自己到底要的是什么才是关键。

所以我只列了三个问题给他:


  1. 想象一下,十年后,当你35岁的时候,你会是一个什么样子的人?在哪里工作,在做什么工作,生活是什么样子的,别人谈论到35岁的你是什么一个评价,等等?描述得详细一点。

  2. 过去两三年,工作什么事情让你觉得快乐、有成就感、没有虚度年华?将来两三年,工作上什么事情会让你觉得快乐、有成就感、没有虚度年华?

  3. 你会在"我要成为___那样的人"里面填谁?如果可以让你填三个人,你会填哪三个?为什么?你觉得自己应该怎么做才能成为那样的人?
~
~
~

宫保鸡丁

        不是本科吃了四年的大美的宫保鸡丁啦,是陶哲的歌~~,这个鸡丁前面的歌曲居然是!!我的小毛驴- - ,CFT~~,这个曲子让我想起了好多东东~~。听着这曲子就像回到了N年前,高三前4个快乐MM逃课出去玩的情景。四个人跑到高速公路旁边的小湖那里吓超级大的喜鹊,打水漂~~,撒把骑车,在一级公路拉着横排高唱“我的小毛驴~~”。家乡的阳光依旧、蓝天依旧。但这四个MM倒是很难聚在一起了~~。一个留在北京,两个在家乡教书,各忙各的,也很难聚了。剩下一个,继续流浪~~........

又到一年毕业时~~

       今天研三的答辩就全部结束了。我们也将荣升为“研三”的。回想去年的这个时候,还对研究生的两年时光充满憧憬呢,研究生生活就像一个打开一条缝隙的盒子,露出的微光让人兴奋。而今,这个盒子已经完全打开了,光芒也即将散去,我已经知道在毕业前应该认真做好什么。一定要做的。还有选作的.嘿嘿。
   
        不同方向的目标,一个一个搞定.......

回家休息两天:)

    忙里偷闲,趁着周六周日,跑回家里两天。在家里呆着好幸福啊,前几天太累了,还真的好好休整一下。
  
   下周就师兄师姐们就要答辩了,他们的研究生生活马上就要结局了。而我们充满期待和挑战的生活即将开始~~~~


  a za a za ~