C #: rules for naming protected member fields

In our .NET software component, we use the following naming convention. When a client uses our DLL from VB.NET, the compiler cannot distinguish a member field distancefrom a property distance. What workaround do you recommend?

Thank.

public class Dimension : Text
{
    private string _textPrefix;

    protected double distance;

    /// <summary>
    /// Gets the real measured distance.
    /// </summary>
    public double Distance
    {
        get { return Math.Abs(distance); }
    }
}
+4
source share
2 answers

, . . . , ( ). , , .

, :

public class Dimension : Text
{
    private string _textPrefix;

    private double _absoluteDistance;

    /// <summary>
    /// Gets the real measured distance.
    /// </summary>
    public double Distance
    {
        get { return _absoluteDistance  }
        protected set { _absoluteDistance = Math.Abs(distance);
    }
}

get set, . , :

public class Dimension : Text
{
    private string _textPrefix;

    /// <summary>
    /// Gets the real measured distance.
    /// </summary>
    public double Distance { get; private set; }

    protected void SetAbsoluteDistance(double distance)
    {
        Distance = Math.Abs(distance);
    }
}
+7

, , , - :

public class Dimension : Text
{
    private string _textPrefix;

    private double _rawDistance;

    /// <summary>
    /// Gets the real measured distance.
    /// </summary>
    public double AbsoluteDistance
    {
        get; private set;
    }

    /// <summary>
    /// Gets the raw distance
    /// </summary>
    public double RawDistance
    {
        get { return _rawDistance; }
        protected set { _rawDistance = value; AbsoluteDistance = Math.Abs(value); }
    }
}

RawDistance , AbsoluteDistance, - Math.Abs() getter " ".

+2

All Articles