If I have a class that stores a DateTime:
class LogEntry
{
readonly DateTime dateTime;
public LogEntry(DateTime dateTime)
{
this.dateTime = dateTime;
}
public DateTime ?????
{
get
{
return dateTime;
}
}
}
What should I name the DateTime property? Or should I split the property into 2 properties: 1) Date 2) Time?
edit: I was looking for a property name that provides inference that its value is both a date and a time, not a property specific to log entries (e.g., DateCreated doesn't provide any inference that it also shares the time the entry was created and vice versa).
If you use TIMESTAMP then you don't have to specify a column name and SQL Server will create a column "TimeStamp" for you. But it is recommended to use "ROWVERSION" data type and in this case you have to specify the column name.
Always use camelCase with method arguments and local variables. Don't use Hungarian notation for variables. Note: Don't use abbreviations for any words and don't use underscore ( _ ) in between any name. Use PascalCase for property.
C# DateTime is a structure of value Type like int, double etc. It is available in System namespace and present in mscorlib. dll assembly. It implements interfaces like IComparable, IFormattable, IConvertible, ISerializable, IComparable, IEquatable.
Explanation: The DateTime class has 11 constants, no static properties or methods.
Assuming LogEntry
is used for logging, here is how some other logging platforms do it:
log4net calls it TimeStamp
in the LoggingEvent class.
NLog calls it TimeStamp
in the LogEventInfo class.
Enterprise Library calls it TimeStamp
in the LogEntry class.
Microsoft calls it DateTime
in the TraceEventCache class.
(TraceEventCache
is passed into TraceListener
Trace*
calls. DateTime
is the time at which the logging message was generated.)
LogDate
CreatedDate
EntryDate
StarDate // **
Pick a name that you feel describes the property best. And, no, do not split the property.
TimeStamp
maybe?
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