访问类变量 [英] access class variable
本文介绍了访问类变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个班级A,B,C
我想要C班变量可以访问A类但不能访问B类。如果没有继承,怎么能实现呢?
关于序列化
我有3个现在已经序列化的xml对象我只想要2个对象反序列化它怎么可能?
问候,
sjs
Hi,
I have 3 classes A,B,C
I want class C variable to be access to class A but not to class B. How can be achieve that without inheritance?
Regarding Serialization
I have 3 xml object which is already serialize now I want only 2 object to deserialize how can it be possible?
Regards,
sjs
推荐答案
你不能,除非他们在不同的集会中。
您有五种无障碍选择:
私人
- 仅限同一班级
protected internal
- 在包含的类中,以及从包含类派生的类
internal
- 在同一个程序集中
protected
- 在类中,仅派生类
public
- 可在任何地方访问,但任何人
没有规定将其限制为特定的类名。
You can''t, unless they are in different assemblies.
You have five options for accessibility:
private
- within the same class only
protected internal
- within the containing class, and classes derived from the containing class only
internal
- within the same assembly
protected
- within the class, and derived classes only
public
- accessable anywhere, but anyone
There is no provision for limiting it to specific class names.
使C类变量内部(访问修饰符)并将A类和C类放在一个其他dll中的dll和B类。
你可以使用`internal`访问修饰符来使这个类/变量可以访问
同一程序集中的其他类,但在程序集外部无法访问。
对于序列化,您可以使用ISerializable Interface编写自定义序列化逻辑。
Make class C variables internal (access modifier) and place class A and C in one dll and Class B in other dll.
Can you place you can use the `internal` access modifier which will make this class/variables accessible to the
other classes in the same assembly, but not accessible outside the assembly.
For serialization you can use ISerializable Interface to write custom serialization logic.
这篇关于访问类变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文