zoukankan      html  css  js  c++  java
  • ??运算符,你是干嘛用的

    ?运算符,大家应该熟知,两个作用

    1、三元运算符x==true?y=1:y=-1 

    2、.Net里面定义空类型的一种表示 int?表示int型可以含空置

    那么??干什么用的呢!!!

    其实他是?运算符的综合体,我个人这么理解,也便于记忆。

    MSDN上是这样说明的如果 ?? 运算符的左操作数非空,该运算符将返回左操作数,否则返回右操作数。

    例子直接看MSDN上的吧,已经很清晰明了了

    // nullable_type_operator.cs
    using System;
    class MainClass
    {
        static int? GetNullableInt()
        {
            return null;
        }
    
        static string GetStringValue()
        {
            return null;
        }
    
        static void Main()
        {
            // ?? operator example.
            int? x = null;
    
            // y = x, unless x is null, in which case y = -1.
            int y = x ?? -1;
    
            // Assign i to return value of method, unless
            // return value is null, in which case assign
            // default value of int to i.
            int i = GetNullableInt() ?? default(int);
    
            string s = GetStringValue();
            // ?? also works with reference types. 
            // Display contents of s, unless s is null, 
            // in which case display "Unspecified".
            Console.WriteLine(s ?? "Unspecified");
        }
    }
    

      

  • 相关阅读:
    oracle 查看表空间使用率
    解决linux下vim中文乱码问题
    linux 时间同步
    oracle ho与mysql system命令
    mysql 重置root密码
    2020 10 26
    2020 10 24
    2020 10 23
    2020 10 22
    2020 10 21
  • 原文地址:https://www.cnblogs.com/diorlv/p/2284626.html
Copyright © 2011-2022 走看看