C # differs from Java on modifiers

Source: Internet
Author: User
Tags modifiers

The 1.readonly modifier is used only to decorate a data member of a class. As the name says, once they have been written, directly initialized, or assigned in a constructor, the data member can only read it.

The difference between a readonly and a const data member is that const requires you to initialize it directly at the time of declaration.

classMyClass {Const intConstint = -;//Proceed directly    ReadOnly intMyInt =5;//Proceed directly    ReadOnly intMyInt2;  PublicMyClass () {MyInt2=8;//the indirect    }      PublicFunc () {myInt=7;//illegalConsole.WriteLine (myint2.tostring ()); } } 

2.sealed

A class with the sealed modifier does not allow you to inherit any class from it

3.unsafe

You can use the unsafe modifier to define an unsafe context in C #. In an unsafe context, you can insert unsafe code, such as pointers to C + +, etc.

C # differs from Java on modifiers

Related Article

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.