如何在运行时只读对象? [英] how to make an object readonly in runtime?

查看:82
本文介绍了如何在运行时只读对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DataTable对象中有一些数据,我想把它放到一个静态的

数据不应该改变,但默认情况下可以改变DataTable。

有一种简单的方法可以让它只读。我可以创建自己的

包装类来完成这个,但希望有一种方法可以直接在DataTable上实现这个




提前感谢您的帮助

Bob

解决方案

"鲍勃" <博******* @ yahoo.com>在新闻中写道:OWgP0I9gEHA.3348

@ TK2MSFTNGP12.phx.gbl:

我可以创建自己的
包装类来完成此任务但是希望有一种方法可以直接在DataTable上执行此操作。




这可能有效,尝试将表声明为常量并填充数据表

在构造函数中。


或者将数据表声明为私有并提供自己的方法来访问数据表




-

Lucas Tam(RE********@rogers.com)

请删除删除来自回复时的电子邮件地址。
http://成员。 ebay.com/aboutme/coolspot18/


如果是VB,请将类成员声明为Shared并将类本身声明为

NotInheritable 。在构造函数中设置DataTable。

"鲍勃" <博******* @ yahoo.com>在消息中写道

新闻:OW ************** @ TK2MSFTNGP12.phx.gbl ...

我有一些数据我希望将一个DataTable对象放入一个静态的类中,供整个应用程序使用,有点像一个cahced全局值。那里的数据不应该改变,但默认情况下可以更改DataTable。
是否有一种简单的方法可以让它只读。我可以创建自己的
包装类来实现这一目标,但希望有一种方法可以直接在DataTable上执行此操作。

提前感谢您的帮助 Bob



Scott M.< s - *** @ nospam.nospam>写道:

如果是VB,则将类成员声明为Shared,将类本身声明为NotInheritable。在构造函数中设置DataTable。




我不知道如何阻止DataTable的数据发生变化。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要给我发邮件


I have some data in a DataTable object that I''d like to put into a static
class for the entire app to use, kind of like a cahced global value. The
data in there should not change, but DataTable by default can be changed.
Is there an easy way to make it read only. I can probably create my own
wrapper class to accomplish this but hopefully there is a way to do this
directly on the DataTable.

Thanks in advance for any help
Bob

解决方案

" Bob" <bo*******@yahoo.com> wrote in news:OWgP0I9gEHA.3348
@TK2MSFTNGP12.phx.gbl:

I can probably create my own
wrapper class to accomplish this but hopefully there is a way to do this
directly on the DataTable.



This might work, try declaring the table as constant and fill the datatable
in the constructor.

Or declare the datatable as private and provide your own methods for
accessing the datatable?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


If VB, declare the class members as Shared and the class itself as
NotInheritable. Set up the DataTable in the constructor.
" Bob" <bo*******@yahoo.com> wrote in message
news:OW**************@TK2MSFTNGP12.phx.gbl...

I have some data in a DataTable object that I''d like to put into a static
class for the entire app to use, kind of like a cahced global value. The
data in there should not change, but DataTable by default can be changed.
Is there an easy way to make it read only. I can probably create my own
wrapper class to accomplish this but hopefully there is a way to do this
directly on the DataTable.

Thanks in advance for any help
Bob



Scott M. <s-***@nospam.nospam> wrote:

If VB, declare the class members as Shared and the class itself as
NotInheritable. Set up the DataTable in the constructor.



I don''t see how that prevents the DataTable''s data from changing.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于如何在运行时只读对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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