In-depth discussion of const, readonly keywords in C #

Source: Internet
Author: User

First of all, these interviews will often be asked by the interviewer, but you answer to the interviewer satisfaction? Of course, if you know these principles, you may not

Afraid of. Since we're talking about the principle, we'll start with MSDN.


A: A few places worth scrutiny

1. Let's take a look at MSDN above on how const is said, we will see. Cannot be modified, compile the constant amount of these critical information.

Why Q:const cannot be modified.

A: This is very simple, and many textbooks say that when the compiler compiles, the values of the constants are stored in the assembly's metadata, and we do an example

Take a look at it.

①: Create a new projecta.


The code is as follows:


ProjectA

public class TestClass

{

public const int Ctrip = Int. MaxValue;

}

Build another mainproject, quoting the next projecta.


The code is as follows:


Using System;

Class Program

{

static void Main (string[] args)

{

Console.WriteLine (Testclass.ctrip);

Console.read ();

}

}

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
In-depth discussion of const, readonly keywords in C #

This address: http://www.paobuke.com/develop/c-develop/pbk23667.html






Related content C # implementation sequence table (linear table) A complete example of how to resolve a hash conflict common misconception of the Equals method in C # Implementation of the method of controlling the volume and mute of the system based on the Add-minus button
C # Methods for reading computer CPU and HDD Information C # Managed heap object instance contains content Analysis C # implementation method for automatically adding copyright annotation information to class and function code C # implementation terminates executing thread

In-depth discussion of const, readonly keywords in C #

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.