gpt4 book ai didi

c# - 没有参数定义但仍然接受参数的构造函数

转载 作者:太空宇宙 更新时间:2023-11-03 18:51:41 26 4
gpt4 key购买 nike

我有一个类调用下面的属性 (RequireTransaction),它接受一个参数,但在类定义中,构造函数的定义没有任何参数。当没有用一个定义的构造函数时,这个属性构造函数如何能够接受一个参数?

[RequiresTransaction(IncludeData = true)]
public ActionResult DoSomething()
{
return something;
};


public class RequiresTransactionAttribute
{
public bool IncludeData { get; set; }

public RequiresTransactionAttribute()
{
IncludeData = false;
}
}

最佳答案

引用the documentation :

Named or optional parameters correspond to either properties or fields of the attribute.

这里的命名参数对应于IncludeData属性,因为是命名参数,所以不需要相应的构造函数参数。

关于c# - 没有参数定义但仍然接受参数的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56764883/

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