示例:定义同时赋初值
public decimal Price { get; set; } = 0;
public bool IsDone { get; set; } = true;
注:逻辑值默认 false
示例:日期类型
public DateOnly Date { get; set; }
public DateTime? Time { get; set; }
示例:字符串
private string GetTitleA() => $"Set by panelData.Title A"; /* panelData.Title 视为 普通 字符串 */
private string GetTitleB() => $"Set by {panelData.Title} B"; /* panelData.Title 视为 变量 */
private string GetTitleC() => "Set by {panelData.Title} C"; /* panelData.Title 视为 普通 字符串 */
示例:数组
string[] Summaries = new[] { "One", "Two", "Three" };
string[] SelectedCars { get; set; } = new string[] { };
string[] SelectedCities { get; set; } = new[] { "bal", "sea" };
注:数组转字符串
@string.Join(", ", SelectedCities)
示例:计算列
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
示例:枚举
public enum ShirtColor
{
Red, Blue, Yellow, Green, Black, White
}