c# - 有没有一种方法可以像在 eclipse 中那样在 visual studio 2012 中生成 getter、setter 函数

标签 c# visual-studio-2012

我在这里查找了解决方案C# shortcut or shorthand getter setter但是当我实现其中一种解决方案时

visual studio 生成的代码如下

private int myVar;

public int MyProperty
{
    get { return myVar; }
    set { myVar = value; }
} 

与自动 getter setter 生成器相比,我想要的是为我的所有变量创建 getter setter 并依赖于使用它们的名称

private int id;

public int Id
{
    get { return id; }
    set { id= value; }
}

这可能吗?

最佳答案

是的,只需创建一个字段,然后Refactor->Encapuslate Field。快捷键是 ctrl + R, E

关于c# - 有没有一种方法可以像在 eclipse 中那样在 visual studio 2012 中生成 getter、setter 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20703458/

相关文章:

c# - 如何使用 C# 消除数据表中的重复条目?

c# - 我如何知道单词列表是项目符号列表还是数字列表?

c# : Why is a cast needed from an Enum to an INT when used in a switch statement? ,枚举是整数

c# - 如何在 C# 中的不同 Active Directory 域中添加用户?

sql - 使用 SSDT 进行单元测试表

.net - 程序集在 x64 配置下正确复制,但在 x86 下不正确

c# - Entity Framework - 单个事务中的父子表更新

c# - 检查用户名是否已存在于数据库中

c++ - penter 和 pexit 的 Visual Studio 宏

c# - 采用 DateTimeOffset 的表达式导致 Visual Studio 内部编译器错误