C# 属性

Code

namespace ConsoleApp
{
    public class Cat
    {
        public string Name1 { get; set; } = "mimi";
        public string Name2 = "mimi";

        public string Name3 { get { return "mimi"; } }
        public string Name4 { get; } = "mimi";
        public string Name5 => "mimi";
    }
}

1、2一样,可以get set
3、4、5一样,都是只读属性,只不过是语言版本不同的写法

Ref

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members

posted @ 2024-05-10 15:44  talentzemin  阅读(4)  评论(0编辑  收藏  举报