这是来自流行的 EmguCV 包的类签名。这是 Image
类 - 并不是所有的都很重要:
/// <summary>
/// An Image is a wrapper to IplImage of OpenCV.
/// </summary>
/// <typeparam name="TColor">Color type of this image (either Gray, Bgr, Bgra, Hsv, Hls, Lab, Luv, Xyz, Ycc, Rgb or Rbga)</typeparam>
/// <typeparam name="TDepth">Depth of this image (either Byte, SByte, Single, double, UInt16, Int16 or Int32)</typeparam>
public partial class Image<TColor, TDepth>
: CvArray<TDepth>, IImage, IEquatable<Image<TColor, TDepth>>
where TColor : struct, IColor
where TDepth : new()
具体注意
...
where TDepth : new() // <-- either Byte, SByte, Single, double, UInt16, Int16 or Int32
new()
如何将类型参数 TDepth
限制为 .NET 整数类型?
最佳答案
事实并非如此。根据 documentation,所有 new()
保证是具有约束的泛型类型(在本例中为 TDepth
)必须提供无参数构造函数并且它不是抽象的.
关于c# - 用 `new()` 约束类型参数是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31302408/