只读构造函数 [英] Read-Only Constructor
问题描述
那么,在.NET
框架中是否存在称为只读构造函数的东西?有人向我提到了这个词,我一直试图从中获取理由。我甚至没有在网上获得链接。
So, is there something called a Read-Only constructor in the .NET
framework? Someone mentioned the term to me and I''ve been trying to
make sense out of it. I didn''t get a link on the Web even.
推荐答案
Sathyaish写道:
Sathyaish wrote:
所以,.NET
框架中是否存在称为只读构造函数的东西?有人向我提到了这个词,我一直在试图理解它。我甚至没有在网上获得链接。
So, is there something called a Read-Only constructor in the .NET
framework? Someone mentioned the term to me and I''ve been trying to
make sense out of it. I didn''t get a link on the Web even.
我认为你需要查看该术语的来源,因为它
根本没有任何意义。
财产只能在你不能写的意义上阅读:
obj.PropName = newValue;
并让它编译。<br />
另一方面,构造函数是一个方法,所以它是打电话,不读书或
写给。
-
Lasse V?gs?ther Karlsen
< a rel =nofollowhref =http://usinglvkblog.blogspot.com/target =_ blank> http://usinglvkblog.blogspot.com/
mailto: la***@vkarlsen.no
PGP KeyID:0x2A42A1C2
I think you need to check with the source of that term because it
doesn''t make any sense at all.
A property can be read only in the sense that you can''t write:
obj.PropName = newValue;
and get it to compile.
A constructor on the other hand is a method so it is called, not read or
written to.
--
Lasse V?gs?ther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
也许您正在引用可用于的readonly关键字make
字段readonly除了构造函数:
class MyClass {
public readonly int myAge; //只能由构造函数分配
public MyClass(int age){
myAge = age;
}
}
" Sathyaish"写道:
Perhaps you''re refering to the readonly keyword that can be used to make
fields readonly except from the constructor:
class MyClass {
public readonly int myAge; // can only be assigned to by the constructor
public MyClass(int age) {
myAge = age;
}
}
"Sathyaish" wrote:
那么,在.NET
框架中是否存在称为只读构造函数的东西?有人向我提到了这个词,我一直在试图理解它。我甚至没有在网上获得链接。
So, is there something called a Read-Only constructor in the .NET
framework? Someone mentioned the term to me and I''ve been trying to
make sense out of it. I didn''t get a link on the Web even.
" Sathyaish" < SA ******* @ gmail.com> schrieb:
"Sathyaish" <sa*******@gmail.com> schrieb:
那么,在.NET
框架中是否存在称为只读构造函数的东西?有人向我提到了这个词,我一直在试图理解它。我甚至没有在网上找到链接。
So, is there something called a Read-Only constructor in the .NET
framework? Someone mentioned the term to me and I''ve been trying to
make sense out of it. I didn''t get a link on the Web even.
我建议你提供一些你想要的更多细节。
>
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://classicvb.org/petition/>
I suggest to provide some more details on what you want to archieve.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
这篇关于只读构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!