从私有变量或类功能的实际使用物业的价值?变量、实际、物业、价值

由网友(清川带长薄)分享简介:当从一个函数的类中引用类的属性你使用从实际财产或私有变量值的价值呢?哪种方法是最好的?为什么呢?公共类私人m_Foo为双公共财产美孚()为双得到返回m_Foo最终得到集(BYVAL值作为双)m_Foo =价值最终设置高端物业公共函数bar()为双昏暗x作为双= 5 * m_Foo昏暗y为双= 3 *富端功能末级解决方案...

当从一个函数的类中引用类的属性你使用从实际财产或私有变量值的价值呢?

哪种方法是最好的?为什么呢?

 公共类

  私人m_Foo为双

  公共财产美孚()为双
    得到
      返回m_Foo
    最终得到
    集(BYVAL值作为双)
      m_Foo =价值
    最终设置
  高端物业

  公共函数bar()为双
    昏暗x作为双= 5 * m_Foo
    昏暗y为双= 3 *富
  端功能

末级
 

解决方案

就个人而言,我尝试使用get / set访问尽可能避免奇怪我自己,当我改变自己的逻辑和突然的地方,我进入的是私人领域的唐T正常工作。

钱从哪来 如何影响经济和资产价格 货币创造之理论篇

When referencing class properties from a function within the class do you use the value from the actual property or the private variable value?

Which way is best? Why?

public class

  private m_Foo as double

  public property Foo() as double
    get
      return m_Foo
    end get
    set(byval value as double)
      m_Foo = value
    end set
  end property

  public function bar() as double
    Dim x as double = 5 * m_Foo
    Dim y as double = 3 * Foo
  end function

end class

解决方案

Personally, I try to use the get/set accessor whenever possible, to avoid surprising myself when I change their logic and suddenly places where I access the private field don't work as expected.

阅读全文

相关推荐

最新文章