Website project Unsafe code may only appear if compiling with/unsafe error Solution

Source: Internet
Author: User
C # In order to simplify development, the direct management of memory is hidden, but sometimes we also need direct memory operations, so unsafe CodeThe block came into being.
In general, we do not need to use the Unsafe code in the. NET Framework, but we need to use it in some application cases, as shown below:
Timely application Program: We may need pointers to provide program functions;
External Method: A pointer is required to be used as a parameter in a non-. Net DLL, for example, in a Windows API written in C language;
Debugging: Sometimes we need to check the memory content for debugging purposes, or you may need to write a program to analyze the status of a processing process or memory;

Next I will continue to introduce the conditions for using the Unsafe code. Due to the long digest, I will only give a brief description of the unsafe code. The following describes the most troublesome aspects in use, that is, the error encountered when using unsafe code. We may encounter this error:

Error cs0227: Unsafe code may only appear if compiling with/unsafe

In fact, it is not your code error. To use the Unsafe code in vs.net, we must set it in the properties of the project. The setting method is as follows:

Click project properties-> Configure properties-> Generate-> General: Insecure code is allowed (hooked up)

Now you can use the Unsafe code normally.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.