const static readonly等关键字的区别(欢迎高手指正我的总结)
2008-05-10 10:58
351 查看
本文记录会非常凌乱乃至混乱,因为属于个人理解的思考图,属于C#关键字之间相互串接思考(还可能夹杂别的语言)。
const: 常量,编译时候确定。内存中,随着类型不同而存在heap,stack中。
static: 对于类或类中,它不用被实例化就能使用。 (同时对于C++,这个时候它不能被extern)理解中它应该存在类似C那样的全局静态区中。
readonly: 跟const很像,但是却必须在构造函数中定义。它只在类被实例化的时候才产生。(如果是类有静态构造函数,是否在编译的时候产生?)
static const:编译时确定,如果在类中,不用实例化类就能使用。(放在heap中?)
static readonly:到现在为止我所知道的,这个只用在在为了保证:在公有类中,定义一个static readonly field,它只在类实例化后一次确定,以后则不能更改。
C#在类中,变量和常量通常叫field,而使用get,set来完成变量赋值读取的就叫properties,跟methods又有不同。
此文不保证准确性,但希望随着以后的深入学习,我能够很准确地指出来。
const: 常量,编译时候确定。内存中,随着类型不同而存在heap,stack中。
static: 对于类或类中,它不用被实例化就能使用。 (同时对于C++,这个时候它不能被extern)理解中它应该存在类似C那样的全局静态区中。
readonly: 跟const很像,但是却必须在构造函数中定义。它只在类被实例化的时候才产生。(如果是类有静态构造函数,是否在编译的时候产生?)
static const:编译时确定,如果在类中,不用实例化类就能使用。(放在heap中?)
static readonly:到现在为止我所知道的,这个只用在在为了保证:在公有类中,定义一个static readonly field,它只在类实例化后一次确定,以后则不能更改。
C#在类中,变量和常量通常叫field,而使用get,set来完成变量赋值读取的就叫properties,跟methods又有不同。
此文不保证准确性,但希望随着以后的深入学习,我能够很准确地指出来。
相关文章推荐
- [自学问题总结]const 和 static readonly 区别
- [C# FAQ]const和static readonly的区别
- .net程序员的盲点(三):const和static readonly的区别
- .net程序员的盲点(三):const和static readonly的区别
- C#中的const与static readonly区别
- What is the difference between const and static readonly?(const 和 static readonly 的区别?)
- const和static readonly 区别
- C++知识点总结(上):指针和引用,static关键字,const关键字,malloc\free和new\delete的区别等
- c# 中const 和 static readonly 的区别
- C#中const与 static readonly 区别(转)
- C#中const与static readonly的区别
- C#Readonly, static, const 区别<转载>
- const和static readonly的区别
- static readonly与const的区别!
- const 和 static readonly 区别?
- ASP.NET 中 const 与 static readonly 的区别
- C#老生常谈之const与static readonly只区别
- const 和 static readonly 区别?
- C#中Const与Static Readonly的区别
- C# FAQ: const和static readonly有什么区别?