Use private or use properties? C#

c#, private, properties

Solution

Use the properties, and if you're on C# 3 you should use automatically implemented properties like this:

public string Fee
{
    get; private set;
}

public string Receipt
{
    get; private set;
}

public MyValue(string fee, string receipt) : this()
{
    this.Fee = int.Parse(fee).ToString();
    this.Receipt = receipt;
}

Problem

Note that the following code is in a class a single class ``` private string _fee; private string _receipt; public string Fee { get { return _fee; } private set { _fee = value; } } public string Receipt { get { return _receipt; } private set { _receipt = value;} } public MyValue(string fee, string receipt) : this() { _fee = int.Parse(receipt).ToString(); _receipt = receipt; } ``` As you can see my property does nothing so should I use ``` _fee = int.Parse(fee).ToString(); _receipt = receipt; ``` or ``` Fee = int.Parse(fee).ToString(); Receipt = receipt; ```

Original source