什么是{搞定;组; }在C#语法? [英] What is the { get; set; } syntax in C#?

查看:127
本文介绍了什么是{搞定;组; }在C#语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习ASP.NET MVC,我能阅读英文文件,但我真的不明白这有什么code发生了什么:

I am learning ASP.NET MVC, and I can read English documents, but I don't really understand what is happening with this code:

public class Genre
{
    public string Name { get; set; }
}

这是什么意思?({获取;设置;})

推荐答案

这是一个所谓的自动属性,本质上​​是以下的简写(类似于code会被编译器生成):

It's a so-called auto property, and is essentially a shorthand for the following (similar code will be generated by the compiler):

private string name;
public string Name
{
    get
    {
        return this.name;
    }
    set
    {
        this.name = value;
    }
}

这篇关于什么是{搞定;组; }在C#语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆