3

我有这门课,你在下面的答案中看到。在那里我可以参考例如Valuewith<see cref="Value"/>和类本身 with <see cref="GenericEventArgs{T}"/>

  1. 我如何引用默认值(T)?甚至可能吗?
  2. 如何引用构造函数?

/// <summary>
/// A simple <see cref="EventArgs"/> class that can contain a value.
/// </summary>
/// <typeparam name="T">Type of <see cref="Value"/>.</typeparam>
public class GenericEventArgs<T> : EventArgs
{
    /// <summary>
    /// Instantiates a <see cref="GenericEventArgs{T}"/> with 
    /// <see cref="default"/> default as Value.
    /// </summary>
    public GenericEventArgs()
        : this(default(T)) {}


    /// <summary>
    /// Instantiates a <see cref="GenericEventArgs{T}"/>
    /// </summary>
    /// <param name="value"></param>
    public GenericEventArgs(T value)
    {
        Value = value;
    }


    /// <summary>
    /// The value.
    /// </summary>
    public T Value { get; private set; }
}
4

2 回答 2

1

.net 文档本身将其称为:“值参数类型的默认值”。

请参阅Dictionary.TryGetValue的文档

于 2009-04-21T11:11:10.360 回答
0

不,我认为这是不可能的。由于该类在运行时使用正确的类型进行了 JIT,因此文档与使用的实际类型无关。如果您使用类约束,您可以用“null”替换默认值。

于 2009-04-21T11:06:53.710 回答