这是什么意思 ?公共名称{get;放;} [英] What does this mean ? public Name {get; set;}

查看:16
本文介绍了这是什么意思 ?公共名称{get;放;}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在 C# 文档中看到这种安静.但它有什么作用?

I see this quiet often in C# documentation. But what does it do?

public class Car
{
   public Name { get; set; }
}

推荐答案

简写为:

private string _name;

public string Name
{
    get { return _name; }
    set { _name = value; }
}

编译器生成成员变量.这称为自动属性.

The compiler generates the member variable. This is called an automatic property.

这篇关于这是什么意思 ?公共名称{get;放;}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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