c# - .NET 中的可空类型

标签 c# .net

 protected static SqlParameter CreateParameter(string name, object value, bool skipEmpty, bool isOutput =false)
 {
    if (skipEmpty && value is string && string.IsNullOrEmpty((string)value))
        return null;
    //1
    if (skipEmpty && value is int? && value == null)
      return null;
    //2
    if (skipEmpty && value is Guid? && value == null)
      return null;
    //....................
}

resharper 说 1 和 2 子句总是错误的。但是为什么?

最佳答案

如果值为 null,则不可能从中推断出比 object 更复杂的类型,因此它永远不可能是 int?Guid?

关于c# - .NET 中的可空类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5511670/

相关文章:

c# - 继承 WCF 服务中其他接口(interface)的接口(interface)

c# - 解决 C# 中的线程冲突

c# - 使用 Web 服务客户端/ClientBase 检测无效的 XML 响应

c# - 宏调用后通过 C# 检测/关闭 excel 消息框

.net - 如何在 Visual Studio 2010 中添加 PNG 资源?

c# - 无法将属性或索引器 'AnonymousType#1.FirstName' 分配给 -- 它是只读的

c# - 使用 HtmlAgilityPack C# 检索特定 URL

c# - UpdatePanel 中的 AddThis 控件 - 确保它们在异步回发后正确呈现

c# - 检查 "Server"服务是否正在运行 - 多语言 C#.Net

c# - .Net 压缩文件