[C # Learning] Insecure code,

Source: Internet
Author: User

[C # Learning] Insecure code,

Today, I wrote a technical essay on the first day, but it was not easy to write. I hope readers can understand it.

These two days I learned the Insecure code in C #. When I heard this name, I first thought of why I had to use this function since it was not secure. Why? In fact, this is the same as the fact that many things exist or are handled in our real life. If the goal is more advantageous than the disadvantage, there is a reason to choose it. The so-called Insecure code is not a poor code, but the execution of such code is not completely managed by the Common Language Runtime (CLR), that is, unmanaged code, this type of code does not have the same control and constraints as the managed code. Because it is not fully controlled by CLR, it cannot be tested to ensure that it does not perform harmful operations, so it is called "Insecure code ".

The main purpose of Unsafe code in C # is to use pointers. Because pointers are insecure, managed code does not support pointers, but for some specific types of programming work, use pointers to implement high-performance system code.

In C #, the usage and declaration of pointers are the same as those in C/C ++. Note that any code that uses pointers must be marked as insecure by using unsafe. You can mark types (such as classes or structures), members, or individual code blocks as insecure. As shown below:

1 using Syetem; 2 class Test {3 public int num; 4 public Test (int I) 5 {6 num = I; 7} 8} 9 10 class EixedCode {11 unsafe static void Main () 12 {13 Test o = new Test (2); 14 fixed (int * p = & ol. num) {// when a pointer is used, the fixed modifier is usually used to prevent the garbage collector from moving the hosted code. Here, the fixed modifier blocks the moving object o15 console. writeLine ("vale"); 16 17} 18} 19}

We will not review the pointer content here. We are here today. Thank you for reading it.

 


What is C/O?

C/o

The following results are explained in the dictionary by the Dian Tong.

Abbreviation abbr.
1.
= Care of transferred)
2.
= Carried over [accounting] carry forward the next page; transfer delivery (exchange term)
3.
= Cash order [accounting] refers to the promissory notes, pay-as-you-go tickets, cash tickets, and cash orders.

[C Language] Is there a function that can clear keys in the cache?

Fflush (stdin)
Clear standard input Cache

# Include "stdio. h"
Main ()
{
Char a, B;
Scanf ("% c", & );
// Fflush (stdin );
Scanf ("% c", & B );
Printf ("\ n % c", a, B );
}

You can try it. If there is no fflush (stdin), if you enter a string of characters "abcd", a = 'A', B = 'B'
If fflush (stdin) exists, after entering "abcd", the program continues to wait for the input, and then enters "efdfsd". The result is a = 'A', B = 'E'

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.