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

推荐订阅源

MongoDB | Blog
MongoDB | Blog
Recorded Future
Recorded Future
Jina AI
Jina AI
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
博客园 - 【当耐特】
雷峰网
雷峰网
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
有赞技术团队
有赞技术团队
L
Lohrmann on Cybersecurity
P
Proofpoint News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
P
Privacy & Cybersecurity Law Blog
Scott Helme
Scott Helme
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Hacker News - Newest:
Hacker News - Newest: "LLM"
NISL@THU
NISL@THU
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog RSS Feed
Cyberwarzone
Cyberwarzone
K
Kaspersky official blog
F
Full Disclosure
Martin Fowler
Martin Fowler
Spread Privacy
Spread Privacy
D
Docker
C
Cisco Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page

博客园 - Achilles.NET

路过 通过javascript获得当前窗口页面的宽高度 SQL SERVER设置重新构造字段值大小写敏感 - Achilles.NET - 博客园 修改SQL默认不区分大小写字段值规则 [转帖]Transact-SQL编程规范 Version 1.1 C#调用存储过程返回值 - Achilles.NET - 博客园 Ghost备份后找不到gho镜像文件的解决办法 GridView数据突出颜色显示解决办法 GridView中空记录不显示表头的解决方案[作者不祥] Temple js控制标题闪动 山西DOT NET俱乐部 WEB弹出窗口打印 打印脚本 DataGrid分页 妻子让老公死心塌地的绝招 下班无聊,随便YY ERP──Enterprise Resource Planning 企业资源计划系统 extern(C# 参考)
const(C# 参考)
Achilles.NET · 2007-03-07 · via 博客园 - Achilles.NET

C# 程序员参考 
const(C# 参考) 

const 关键字用于修改字段或局部变量的声明。它指定字段或局部变量的值是常数,不能被修改。例如:


        const int x = 0;
public const double gravitationalConstant = 6.673e-11;
private const string productName = "Visual C#";
备注

常数声明的类型指定声明引入的成员类型。常数表达式必须产生具有目标类型或者可隐式转换为目标类型的类型的值。

常数表达式是在编译时可被完全计算的表达式。因此,对于引用类型的常数,可能的值只能是 string 和 null。

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


public const double x = 1.0, y = 2.0, z = 3.0;
不允许在常数声明中使用 static 修饰符。

常数可以参与常数表达式,如下所示:


public const int c1 = 5;
public const int c2 = c1 + 100;
注意
readonly 关键字与 const 关键字不同。const 字段只能在该字段的声明中初始化。readonly 字段可以在声明或构造函数中初始化。因此,根据所使用的构造函数,readonly 字段可能具有不同的值。另外,const 字段是编译时常数,而 readonly 字段可用于运行时常数,如下面的代码行所示:public static readonly uint l1 = (uint)DateTime.Now.Ticks;
 

示例


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

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

    static void Main()
    {
        SampleClass mC = new SampleClass(11, 22);  
        Console.WriteLine("x = {0}, y = {1}", mC.x, mC.y);
        Console.WriteLine("c1 = {0}, c2 = {1}",
                          SampleClass.c1, SampleClass.c2 );
    }
}
输出
x = 11, y = 22
c1 = 5, c2 = 10
该示例说明如何将常数用作局部变量。


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