gpt4 book ai didi

c# - c#中的参数属性

转载 作者:搜寻专家 更新时间:2023-10-31 08:18:24 28 4
gpt4 key购买 nike

如何使用 C# 属性执行以下操作。下面是 Java 的一个片段,它在构造函数中注释参数。

public class Factory {
private final String name;
private final String value;
public Factory(@Inject("name") String name, @Inject("value") String value) {
this.name = name;
this.value = value;
}
}

从 C# 注释来看,我似乎无法注释参数。这可能吗?

最佳答案

绝对可以属性参数:

public Factory([Inject("name")] String name, [Inject("value")] String value)

当然必须声明该属性,以允许通过AttributeUsageAttribute(AttributeTargets.Parameter) 为参数指定它。

参见 OutAttributeDefaultParameterValueAttribute作为例子。

关于c# - c#中的参数属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2721194/

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