我们知道:
int? number = 10;
Console.WriteLine(number is int); // true
Run Code Online (Sandbox Code Playgroud)
但:
NotNull<string> text = "10"; // NotNull<> is my struct
Console.WriteLine(text is string); // false
Run Code Online (Sandbox Code Playgroud)
我想要text is string回归真实,我该怎么做?
--------------------------------编辑
这是我的NotNull:
public class NotNull<T> where T : class
{
public T Value { get; }
private NotNull(T value)
{
this.Value = value;
}
public static implicit operator T(NotNull<T> source)
{
return source.Value;
}
public static implicit explicit NotNull<T>(T value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
return new …Run Code Online (Sandbox Code Playgroud) 我在http://referencesource.microsoft.com/#mscorlib/system/boolean.cs上找到了布尔源代码:
public struct Boolean
{
...
private bool m_value;
...
}
Run Code Online (Sandbox Code Playgroud)
为什么它不抛出StackOverflowException?
c# ×2