gpt4 book ai didi

C# Generic - 任何声明 T 具有属性的方法?

转载 作者:太空狗 更新时间:2023-10-29 21:41:37 25 4
gpt4 key购买 nike

[MyCustomClassAttribute]
public class Foo
{
}


public class Bar<T>
where T : ??
{
public T FooInstance;
}

我很确定这是不可能的,但我只是想检查一下。有什么方法可以使 T 必须有一个 [MyCustomClassAttribute] 吗?

最佳答案

这恐怕是不可能的。这是所有 possible generic constraints 的列表你可以使用。

关于C# Generic - 任何声明 T 具有属性的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6256527/

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