从另一个类访问局部类的属性 [英] Accessing property of partial class from another class

查看:55
本文介绍了从另一个类访问局部类的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在我的项目中遇到问题,我在一个局部类中有一个getter和setter属性,我想在另一个类中访问它(aspx.cs文件).

局部类是一个库类文件,结构是这样的

Hi,

I am facing a problem in my project, i have a getter and setter property in one partial class and i want access that in another class(aspx.cs file).

The partial class is a library class file the structure is like this

public partial class OneClass
{
        private int a;

        public int A
        {
            get{ return a; }
            set { a = value; }
        }
}



在另一个类ClassClass中,我想访问类ClassClass的公共属性.问题是TwoClass无法从OneClass继承.

请帮助我解决问题,在此先谢谢您!



and in another class TwoClass i want to access the public property of Class OneClass. The problem is TwoClass cannot inherit from OneClass.

Please help me to solve the issue, Thanks in advance!!

推荐答案

如果您可以访问中的相关OneClass对象,则可以访问TwoClass中的OneClass的公共属性. TwoClass.您可以通过
执行此操作(如果您忽略继承作为选项) 1.将OneClass对象传递给TwoClass或
2.通过将其作为TwoClass成员并在适当的时间进行填充.
You can access public properties of OneClass in TwoClass if you can able to access the related OneClass object in TwoClass. And this you can do (if you ignore inheritance as option) by either
1. passing the OneClass object to TwoClass or
2. by having it as TwoClass member and filling it at appropriate time.


TwoClass是同一程序集的一部分吗?如果是,则只需为其创建一个对象,然后您就可以使用该对象访问属性.有点喜欢-
Is the class TwoClass part of the same assembly? If yes, then just create an object of it and you can access the property using the object. Something luke this -
TwoClass objTwoClass = new TwoClass();
//to get value of A
int ValueOfA = objTwoClass.A;
//to set the value of A
objTwoClass.A = 1; //or any int value



在您的问题中我没有明白这一点-问题是TwoClass无法从OneClass继承."? AFAIK,可以继承部分类.



I didn''t get this point in your question - "The problem is TwoClass cannot inherit from OneClass."? AFAIK, the partial classes can be inherited.


这篇关于从另一个类访问局部类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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