惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
博客园_首页
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
D
Docker
博客园 - 司徒正美
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
U
Unit 42
J
Java Code Geeks
A
About on SuperTechFans
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
I
Intezer
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
T
Threatpost
H
Hacker News: Front Page
G
Google Developers Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
S
Secure Thoughts
GbyAI
GbyAI
NISL@THU
NISL@THU
S
Security @ Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Webroot Blog
Webroot Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - newbin

<该停暖气了> stay hungry,stay foolish Stay hungry, Stay foolish... string与stringbuilder的区别 为了实现自我价值,加油,加油! 多态和继承(Inheritance) abstract和interface的异同 [转贴]一名大学生应聘软件工程师的经历和感受 c# brief datagrid,datalist,repeater在Html页中的定义 系统默认提供的CSS样式风格定义 thanks giving 真不知道怎么过 找根火柴棍把眼皮支起来 软件开发的四项基本原则 我们为什么需要 XML Windows 2000的引导过程 Understand CSS Terminology ROUNDTRIP AND POSTBACK 生命如此年轻
关于const的一些解释
newbin · 2004-11-30 · via 博客园 - newbin

const 关键字用于修改字段或局部变量的声明。它指定字段或局部变量的值不能被修改。常数声明引入给定类型的一个或多个常数。

备注

常数声明可以声明多个常数,例如:

public const double x = 1.0, y = 2.0, z = 3.0;

不允许在常数声明中使用 static 修饰符。

常数可以参与常数表达式,例如:

public const int c1 = 5.0;
public const int c2 = c1 + 100;

示例

// const_keyword.cs
// Constants
using System;
public class ConstTest 
{
   class MyClass 
   {
      public int x;
      public int y;
      public const int c1 = 5;
      public const int c2 = c1 + 5;

      public MyClass(int p1, int p2) 
      {
         x = p1; 
         y = p2;
      }
   }

   public static void Main() 
   {
      MyClass mC = new MyClass(11, 22);   
      Console.WriteLine("x = {0}, y = {1}", mC.x, mC.y);
      Console.WriteLine("c1 = {0}, c2 = {1}", MyClass.c1, MyClass.c2 );
   }
}

输出

x = 11, y = 22
c1 = 5, c2 = 10

示例

该示例说明如何将常数用作局部变量。

// const_keyword2.cs
using System;
public class TestClass 
{
   public static void Main() 
   {
      const int c = 707;
      Console.WriteLine("My local constant = {0}", c);
   }
}