gpt4 book ai didi

c# - 如何在 VS2008(自动属性)中使用 "short style"属性设置默认值?

转载 作者:太空狗 更新时间:2023-10-29 20:04:08 27 4
gpt4 key购买 nike

如何为如下定义的属性设置默认值:

public int MyProperty { get; set; }

那是在 VS2008 中使用“prop”[tab][tab](代码片段)。

有没有可能不回到“老路子”?:

private int myProperty = 0; // default value
public int MyProperty
{
get { return myProperty; }
set { myProperty = value; }
}

感谢您的宝贵时间。最好的问候。

最佳答案

只需在构造函数中设置“默认”值即可。

public class Person
{
public Person()
{
this.FirstName = string.Empty;
}

public string FirstName { get; set; }
}

此外,它们被称为自动属性。

关于c# - 如何在 VS2008(自动属性)中使用 "short style"属性设置默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/206611/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com