VB.Net 属性 - 公共获取,私有集 [英] VB.Net Properties - Public Get, Private Set

查看:53
本文介绍了VB.Net 属性 - 公共获取,私有集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我会问......但是有没有办法让属性的 Get 部分公开可用,但保持设置为私有?

I figured I would ask... but is there a way to have the Get part of a property available as public, but keep the set as private?

否则我想我需要两个属性或一个属性和一个方法,只是觉得这会更干净.

Otherwise I am thinking I need two properties or a property and a method, just figured this would be cleaner.

推荐答案

是的,很直接:

Private _name As String

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

这篇关于VB.Net 属性 - 公共获取,私有集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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