c#中 ?? 是什么意思?
来源:互联网 发布:权限域名服务器 编辑:程序博客网 时间:2024/06/02 08:29
refer to :http://www.cnblogs.com/dupeng0811/archive/2009/03/26/1422512.html
c#中 ?? 是什么意思?
string id = Request["id"] ?? string.Empty;
??
判断??左边表达式是否为null,如是null则取右边表达式的值,否则就取左边表达式的值
判断??左边表达式是否为null,如是null则取右边表达式的值,否则就取左边表达式的值
The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.
例子:
// 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");
}
}
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");
}
}
- C#中@是什么意思
- c#中 ?? 是什么意思?
- C#中??和?分别是什么意思
- c#中两个问号(??)是什么意思
- 在C#中??和?分别是什么意思
- 在C#中??和?分别是什么意思?
- 在C#中??和?分别是什么意思?
- 在C#中??和?分别是什么意思?
- 在C#中??和?分别是什么意思?
- 请问C#中get和SET到底是什么意思啊?
- C#语法中两个问号(??)的运算符是什么意思?
- C#中object missing = Type.Missing是什么意思
- C#实体类中在数据类型后面添加问号是什么意思
- c#中函数求值需要运行所有线程是什么意思
- c#中class前面加一个public具体是什么意思
- C#中#define后面直接加一个名词是什么意思?
- c# Args是什么意思?
- c#里面 : this()是什么意思?
- android 记住密码
- java做成 ZIP文件
- Red Black Tree
- git使用笔记1--基本用法
- VisualSVN Server 自动发布配置
- c#中 ?? 是什么意思?
- 如何控制项目中发生的变更?
- JNI Book Studying - Linux
- WinCE Network驱动开发简介
- 一个好多平台对于一个程序员的重要性
- 改进后的Mylist(双链表)--添加了在指定位置后插入,析构里删除节点MyNode
- Linux 下摄像头视频采集与显示
- noj 305 表达式求值 第四届河南省程序设计大赛//待续~~~
- 配置 dev-php