gpt4 book ai didi

c# - 多么简单的得到;放;在一个类意味着?

转载 作者:行者123 更新时间:2023-11-30 19:07:40 27 4
gpt4 key购买 nike

以类中的以下代码为例:

public class Employee : IEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int EmployeeID { get; set; }
}

public class Company : IEntity
{
public string Name { get; set; }
public string TaxID { get; set }
}

我一直用get;并设置;用大括号的东西。我从来没有像这样离开过他们。

只写:

得到;设置;

这是什么意思?

最佳答案

Auto-Implemented Properties

In C# 3.0 and later, auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. They also enable client code to create objects. When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field that can only be accessed through the property's get and set accessors.

关于c# - 多么简单的得到;放;在一个类意味着?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4040733/

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