I’ve got something like this in my property/accessor method of a constructor for my program.
using System;
namespace BusinessTrips
{
public class Expense
{
private string paymentMethod;
public Expense()
{
}
public Expense(string pmtMthd)
{
paymentMethod = pmtMthd;
}
//This is where things get problematic
public string PaymentMethod
{
get
{
return paymentMethod;
}
set
{
if (string.IsNullOrWhiteSpace(" "))
paymentMethod = "~~unspecified~~";
else paymentMethod = value;
}
}
}
}
When a new attribute is entered, for PaymentMethod, which is null or a space, this clearly does not work. Any ideas?
do you perhaps just need to replace
string.IsNullOrWhiteSpace(" ")withstring.IsNullOrWhiteSpace(value)?From your posted code, you need to call:
instead of
The capital p will use your property instead of the string directly. This is why it’s a good idea to use
this.when accessing class variables. In this case, it’s the capital not thethis.that makes the difference, but I’d get into the habit of usingthis.