I currently have the following class with getters and setters as such
public class CustAccount
{
public string Account { get; set; } private string account;
public string AccountType { get; set; } private string accountType;
public CustSTIOrder(Account ord)
{
account = ord.Account;
accountType = ord.AccountType;
}
}
Now I realize that with public string Account { get; set; }
I do not need to declare private string account
. Anyways now my private variable account
contains the value but when I use Account
to obtain the value I get a null. Any suggestions on why I am getting a null ?
Since you're using an auto property, you should be using Account
for all references to the property.
If you're looking to use a backing field, then you'll need to have the backing field (account
) in the get
and set
.
Example:
public string Account
{
get { return account; }
set { account = value; }
}
private string account;
Example of use for the auto property:
public CustSTIOrder(Account ord)
{
Account = ord.Account;
// the rest
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With