财产范围 [英] Scope of properties

查看:74
本文介绍了财产范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将属性的get方法设为public,但是set方法

internal,以便它在程序集之外是有效的只读,但

读取 - 在其中写(对C ++朋友最近的东西),这是否可能?b $ b?或者是否有某种方式来实现朋友。效果?

-

Dave

解决方案

Dave写道:
< blockquote class =post_quotes>我想将一个属性的get方法设为public,但是设置内部的
方法使得它在程序集之外是有效的只读但是读取了 - 在其中写(对C ++朋友来说是最接近的东西),这可能吗?或者是否有某种方式来实现朋友。效果?




这可以在C#2中完成,如下所示:


public int MyProperty {

获得{

返回val;

}

内部设置{

val = value; < br $>
}

}


如果你不使用C#2,我建议你使用内部的setter方法(因为

反对财产制定者)而是。

Oliver Sturm

-

专家编程和咨询提供的服务

请参阅 http://www.sturmnet.org (尝试/博客)


啊,这很有趣。请原谅我的无知,但是什么是C#2?


我有VS.NET 2003(又名VS7.0)和.NET 1.1。我知道VS现在是2005年

(测试版),而.NET将很快处于2.0版,代号为Longhorn,或者它是

" Whidbey" ,不,挂在靛蓝上,或者是育空。 - 哦,小男孩,你可以看到我很尴尬。


澄清将非常感激。

-

Dave

" Oliver Sturm"写道:

Dave写道:

我想将一个属性的get方法设为public,但是设置
方法
内部使得它在程序集之外是有效的只读,但是在其中读写(对于C ++朋友来说是最接近的东西),这可能吗?或者是否有某种方式来实现朋友。效果?



这可以在C#2中完成,如下所示:

public int MyProperty {
get {
return val ;
}
内部设置{
val = value;
}

如果您不使用C#2,我建议您使用内部的setter方法(与
对应的属性设置器)。

Oliver Sturm
-
提供专家编程和咨询服务
请参阅 http://www.sturmnet.org (尝试/博客) )



Dave写道:

啊,这很有意思。原谅我的无知,但是什么是C#2?

我有VS.NET 2003(又名VS7.0)和.NET 1.1。我知道VS现在是2005年(测试版),.NET将很快处于2.0,代号为Longhorn,或者它是Whidbey,不,挂在Indigo上;或者是Yukon - 哦,小男孩,你可以看到
我很困惑。




这些是你提到的很多不同的东西: - )


C#2是随即将推出的VS.NET 2005发布的版本

(现在可用于测试版和各种CTP)。它与.NET框架的

版本相吻合,该版本与同一版本相关联(并且

曾经被称为Whidbey一段时间)。 />

Longhorn是一个操作系统,应该在2006年的b / b $ b $期间发布,它与.NET,VS.NET或C#版本没什么关系。 Indigo

是一项技术,是Longhorn的一部分,即使它可能会将
移植回XP。 Yukon是(或者是?)即将发布的SQL Server 2005版本的代号名称。


现在,为了得到一些混乱 - 大谈现在实际上是C#3,而不是
2,以及相关位,因为这些最近被引入了

普通大众。这个_might_的释放与某种方式重合

Longhorn ...... ;-)

Oliver Sturm

-

提供专家编程和咨询服务

请参见 http://www.sturmnet。组织(尝试/博客)


I would like to make the get method of a property public, but the set method
internal so that it is effectively read-only outside the assembly but
read-write within it (sort of the nearest thing to a C++ "friend"), is this
possible? Or is there some way of achieving the "friend" effect?
--
Dave

解决方案

Dave wrote:

I would like to make the get method of a property public, but the set
method
internal so that it is effectively read-only outside the assembly but
read-write within it (sort of the nearest thing to a C++ "friend"), is this
possible? Or is there some way of achieving the "friend" effect?



This is possible to do in C# 2, like this:

public int MyProperty {
get {
return val;
}
internal set {
val = value;
}
}

If you don''t use C# 2, I''d suggest you use an internal setter method (as
opposed to the property setter) instead.
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)


Ah, that''s interesting. Pardon my ignorance, but what is C# 2?

I have VS.NET 2003 (aka VS7.0) and .NET 1.1. I know that VS is now at 2005
(beta) and that .NET will shortly be at 2.0, codenamed "Longhorn", or is it
"Whidbey", no, hang on "Indigo", or was it "Yukon" - oh boy, you can see I''m
getting confused.

Clarification would be greatly appreciated.
--
Dave
"Oliver Sturm" wrote:

Dave wrote:

I would like to make the get method of a property public, but the set
method
internal so that it is effectively read-only outside the assembly but
read-write within it (sort of the nearest thing to a C++ "friend"), is this
possible? Or is there some way of achieving the "friend" effect?



This is possible to do in C# 2, like this:

public int MyProperty {
get {
return val;
}
internal set {
val = value;
}
}

If you don''t use C# 2, I''d suggest you use an internal setter method (as
opposed to the property setter) instead.
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)



Dave wrote:

Ah, that''s interesting. Pardon my ignorance, but what is C# 2?

I have VS.NET 2003 (aka VS7.0) and .NET 1.1. I know that VS is now at 2005
(beta) and that .NET will shortly be at 2.0, codenamed "Longhorn", or is it
"Whidbey", no, hang on "Indigo", or was it "Yukon" - oh boy, you can see
I''m
getting confused.



These are a lot of very different things you mention :-)

C# 2 is the version that will be released with the upcoming VS.NET 2005
(and is now available in betas and various CTPs). It coincides with the
version of the .NET framework that''s associated with the same release (and
which used to be called Whidbey a while back).

Longhorn is an operating system and should be released sometime during
2006, it doesn''t have much to do with .NET, VS.NET or C# releases. Indigo
is a technology that was developed as part of Longhorn, even if it might
get ported back to XP. And Yukon is (or was?) the code name for the
upcoming release of SQL Server 2005.

Now, to get some confusion back - big talk right now is actually C# 3, not
2, and associated bits, because these were recently introduced to the
general public. The release of this _might_ coincide somehow with
Longhorn... ;-)
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)


这篇关于财产范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆