c#中 ?? 是什么意思?
2012-03-09 15:08
507 查看
refer to :http://www.cnblogs.com/dupeng0811/archive/2009/03/26/1422512.html
string id = Request["id"] ?? string.Empty;
??
判断??左边表达式是否为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");
}
}
c#中
?? 是什么意思?
string id = Request["id"] ?? string.Empty;??
判断??左边表达式是否为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");
}
}
相关文章推荐
- C#中e.Handle是什么意思
- C#中的 int?是什么意思
- C#语法中一个问号(?)和两个问号(??)的运算符是什么意思?zz
- C#中的??是什么意思
- 请问C#中get和SET到底是什么意思啊?
- C#中的 int?是什么意思
- asp.net(c#)中IsPostBack是什么意思
- C# @什么意思
- 【C#】wpf中的xmlns命名空间为什么是一个网址,代表了什么意思
- C#语法中一个问号(?)和两个问号(??)的运算符是什么意思?
- c#中的unchecked是什么意思,起什么作用?
- C# 里面的 #region 是什么意思?
- C#学习之as是什么意思?
- 在C#中internal关键字是什么意思?和protected internal区别
- 在C#中internal关键字是什么意思?
- c#中两个问号(??)是什么意思
- c#里面 : this()是什么意思?
- C#中的parse什么意思?
- c#中这个符号什么意思?(=>)
- c# 类函数static是什么意思?