I have always prefixed my Constants with CN_ as shown below but I am now working on coding to accepted standards, which I found linked on this site. The standards say that I should drop the CN_ for my constants. So with the example below, if I change my CN_NetPrice to NetPrice, I will a conflict with the method property of the same name. Obviously I can’t do that so I am left with a question. Do I have a naming convention problem or is there a problem with my code in general?
public class TicketInformation
{
private const string CN_StartDate = "StartDate";
private const string CN_EndDate = "EndDate";
private const string CN_NetPrice = "NetPrice";
private const string CN_NetTotalPrice = "NetTotalPrice";
private const string CN_Tickets = "Tickets";
public decimal NetPrice { get; set; }
public decimal NetTotalPrice { get; set; }
public decimal Tickets { get; set; }
public static TicketInformation Create(DateTime startDate, DateTime endDate)
{
try
{
TicketInformation ti = new TicketInformation();
using (DataTable dt = DAC.ExecuteDataTable(
"GetAllTicketInformationSelect",
DAC.Parameter(CN_StartDate, startDate),
DAC.Parameter(CN_EndDate, endDate)))
{
ti.NetTotalPrice = Convert.ToDecimal(dt.Rows[0][CN_NetTotalPrice]);
ti.NetPrice = Convert.ToDecimal(dt.Rows[0][CN_NetPrice]);
ti.Tickets = Convert.ToDecimal(dt.Rows[0][CN_Tickets]);
}
return ti;
}
catch (Exception ex)
{
throw new Exception(Convert.ToString(ex));
}
}
}
}
Your constant doesn’t actually represent the net price (etc) does it? It represents the name of the net price column. So I would suggest either:
Or:
Or use an enum:
… calling
ToStringon one of those enum values will give the name.