Re: unsafe?????????

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Jun 17, 11:47 am, "wmhnq" <w...@xxxxxxx> wrote:
private void button1_Click(object sender, EventArgs e)
{
unsafe
{
string str = "abcde";
fixed (char* pStr = str)
{
A a = new A(pStr);
a.change();
MessageBox.Show(str.ToString());
}
}
}
}

public class A
{
unsafe char* pStr = (char*)0;
public unsafe A(char* sss)
{
pStr =sss;
}

public unsafe void change()
{
*pStr = "fghijkl";//error,why??????

}
}

I'm not understanding the need for unsafe code in your example.

.


Quantcast