C # Insecure code,

Source: Internet
Author: User

C # Insecure code,

When a code block is marked with an unsafe modifier, C # allows pointer variables to be used in functions.

Insecure code or unmanaged code is a code block that uses pointer variables.

The following example illustrates how to use a pointer when the unsafe modifier is used in C:

using System;namespace UnsafeCodeApplication{    class Program    {        static unsafe void Main(string[] args)        {            int var = 20;            int* p = &var;            Console.WriteLine("Data is: {0} ",  var);            Console.WriteLine("Address is: {0}",  (int)p);            Console.ReadKey();        }    }}

To compile Unsafe code, you must switch to the command line compiler to specify/UnsafeCommand line.

For example, to compile a program named prog1.cs that contains Insecure code, enter the following command in the command line:

csc /unsafe prog1.cs

If you are using Visual Studio IDE, You need to enable Insecure code in the project properties.

The procedure is as follows:

  • Double-click the properties node in the Solution Explorer to openProject properties).
  • ClickBuildTab.
  • Select option"Allow unsafe code".


See http://www.w3cschool.cc/csharp/csharp-unsafe-codes.html


Zookeeper

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.