Why use private members then use public properties to set them?

后端 未结 5 1539
故里飘歌
故里飘歌 2020-12-11 00:53

Seen a few examples of code where this happens:

public class Foo
{
    string[] m_workID;
    public string[] WorkID
    {
        get
        {
                     


        
5条回答
  •  盖世英雄少女心
    2020-12-11 01:00

    A lot of times you only want to provide read access to a field. By using a property you can provide this access. As you mention you may want to perform operations before the field is accessed (lazy loading, e.g.). You have a lot of code in there that just isn't necessary anymore unless you're still working in .Net 2.0-.

提交回复
热议问题