在Visual Studio中生成Getter和Setter的简单方法 [英] Easy way to generate Getters and Setters in Visual Studio

查看:451
本文介绍了在Visual Studio中生成Getter和Setter的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中是否有生成getter和setter的方法? 我正在尝试使用 Alt + R F ,并且我得到了:

Is there a way to generate getters and setters in Visual Studio? I'm trying with Alt + R, F and i get this:

public String Denomination
{
    get { return denomination; }
    set { denomination = value; }
}

这就是我想要的:

public String getDenomination()
{
    return Denomination;
}

public void setDenomination(String Denomination)
{
    this.Denomination = Denomination;
}

有办法吗?

推荐答案

您可以使用prop代码段创建自动属性.

You can use the prop code snippet to create automatic properties.

键入prop,然后按Tab.然后,您可以更改属性的类型和名称.

Type prop, and press Tab. You can then change the Type and name of the property.

在您的简单情况下,不需要其他逻辑,就不需要备份字段.

In your simple case, where no additional logic is required, there's no needed for backing fields.

这篇关于在Visual Studio中生成Getter和Setter的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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