Try this
private double? _Width;
public double? WidthRound
{
get => _Width;
set
{
if (value != null) _Width = Math.Round(value.Value, 2);
}
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
How can I write the below code shorter, how to optimize? Maybe without function name GetDeviceWhiteParameterSet(); Directly.
? means can be null, right?
[XmlAttribute("length")]
public double? Length { get; set; }
private double _Width;
public double WidthRound // **** not working with ? operator.
{
get { return _Width; }
set { this._Width = Math.Round(value, 2); }
}
public string DeviceWhiteParameterSet => GetDeviceWhiteParameterSet();
public string GetDeviceWhiteParameterSet()
{
string ret = "";
if (DeviceWhiteParameterSet1.Length != 0)
ret += DeviceWhiteParameterSet1;
if (DeviceWhiteParameterSet2.Length != 0)
ret += "|" + DeviceWhiteParameterSet2;
return ret;
}
insertWhite.Parameters.AddWithValue("@Length", length ?? (object)DBNull.Value);
I need this for a database entry. ? operator.
Try this
private double? _Width;
public double? WidthRound
{
get => _Width;
set
{
if (value != null) _Width = Math.Round(value.Value, 2);
}
}