获取Set属性 - 访问修饰符 [英] Get Set property - access modifier

查看:77
本文介绍了获取Set属性 - 访问修饰符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


这个问题让我长时间好奇。

任何人都知道为什么微软不允许使用不同的访问修饰符

for set和get?

更具体地说,为什么他们不允许我们这样做?


静态字符串CSVFileName

{

public get {return _CSVFileName; }

private set {_CSVFileName = value; }

}


通过这种方式,我不需要设置不同的属性或添加功能。

谢谢。

解决方案

他们在2.0;语法是:


公共静态字符串CSVFileName {

get {return _CSVFileName; }

private set {_CSVFileName = value; }

}

Marc


3月29日下午12:58,Eran.Ya ... @ gmail.com写道:


这个问题很长时间好奇我。

任何人都知道为什么微软不允许不同的访问修饰符

for set和get?

更具体地说,为什么他们不允许我们这样做呢?


静态字符串CSVFileName

{

public get {return _CSVFileName; }

private set {_CSVFileName = value; }


}


这样我就不需要设置不同的属性或添加功能了。



我不知道为什么他们没有把它用于.NET 1.1,但它是

可用for .NET 2.0 / C#2。


你会这样做:


公共静态字符串CSVFileName

{

get {return _CSVFileName; }

private set {_CSVFileName = value; }

}


是的,我很高兴它现在可用了。


2007年3月29日04:58:21 -0700, Er ******* *@gmail.com 写道:


>大家好,

这个问题让我长时间好奇。任何人都知道为什么微软不允许使用不同的访问修饰符来设置和获取?
更具体地说,为什么他们不允许我们这样做呢?静态字符串CSVFileName
{

public get {return _CSVFileName; }

private set {_CSVFileName = value; }


这样我就不需要设置不同的属性或添加功能了。

谢谢。



你可以像这样:


public string Foo {

get {

返回m_Foo;

}

内部设置{

m_Foo = value;

}

}


-

Philip Daniels


Hi All,

this issue curious me for long time.
Any one knows why Microsoft didn''t allow to different access modifier
for set and get?
To be more specific, why didn''t they allow us to do it like this?

static string CSVFileName
{
public get { return _CSVFileName; }
private set { _CSVFileName = value; }
}

In this way I don''t need to set different property or add function.
Thanks.

解决方案

They do in 2.0; syntax is:

public static string CSVFileName {
get { return _CSVFileName; }
private set { _CSVFileName = value; }
}
Marc


On Mar 29, 12:58 pm, Eran.Ya...@gmail.com wrote:

this issue curious me for long time.
Any one knows why Microsoft didn''t allow to different access modifier
for set and get?
To be more specific, why didn''t they allow us to do it like this?

static string CSVFileName
{
public get { return _CSVFileName; }
private set { _CSVFileName = value; }

}

In this way I don''t need to set different property or add function.

I don''t know why they didn''t put it in for .NET 1.1, but it''s
available for .NET 2.0/C# 2.

You''d do:

public static string CSVFileName
{
get { return _CSVFileName; }
private set { _CSVFileName = value; }
}

And yes, I''m jolly glad it''s now available :)


On 29 Mar 2007 04:58:21 -0700, Er********@gmail.com wrote:

>Hi All,

this issue curious me for long time.
Any one knows why Microsoft didn''t allow to different access modifier
for set and get?
To be more specific, why didn''t they allow us to do it like this?

static string CSVFileName
{
public get { return _CSVFileName; }
private set { _CSVFileName = value; }
}

In this way I don''t need to set different property or add function.
Thanks.

You can, like this:

public string Foo {
get {
return m_Foo;
}
internal set {
m_Foo = value;
}
}


--
Philip Daniels


这篇关于获取Set属性 - 访问修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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