I have this property
/// <summary>
/// The production date of the device is contained in its serial number.
/// </summary>
public DateTime Date
{
get
{
return SerialNumber.Date;
}
}
However, I would expect I could write it like this
/// <summary>
/// The production date of the device is contained in its serial number.
/// </summary>
public DateTime Date
{
get return SerialNumber.Date;
}
But I receive the error { or ; expected
.
Now my question is: Why do I need braces here, while I do not wish to mark the beginning and end of a scope, as there is only one line of code.
It doesn't really matter that I do need to use braces. But in my opinion its not consistent with the rest of the interpretation of C# code.
You can use
if(DoNotUseBraces) return null;
for example, no braces necessary.
Or even
if (SomeBoolean)
return null;
Again, no braces necessary. I guess its the same as: Why do methods with only one statement need braces? but get does not implement the () like get()
e.g.