将通用属性归为一类 [英] placing common attributes into one class

查看:99
本文介绍了将通用属性归为一类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有五个具有共同属性的类,例如个人详细信息,如何将它们放在一个类中,这样我就不能在所有其他类中重复它们?

I have got five classes with common attributes e.g personal details, how do I place them into one class, so that, I don''t get to duplicate them in all other classes?

推荐答案

您可以创建具有其他类继承自的公共属性的基类.

示例代码:
You can create a base class with your common atributes from which other classes inherits.

Sample code:
<code>Public Class BaseClass


    Private _name As String
    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property



    Sub New()

    End Sub

End Class


Public Class People
    Inherits BaseClass

    Sub New()

    End Sub

End Class</code>


这篇关于将通用属性归为一类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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