public void RestoreTreeView(TreeView treeView, string key) { RestoreTreeViewIndex = 0; RestoreTreeViewExpandedState(treeView.Nodes, (List<bool?>)HttpContext.Current.Session[key + treeView.ID] ?? new List<bool?>()); }
解决方案 »
- 数据迁移
- C/S结构与B/S结构在远程访问方面速度差异大吗?
- 用C#+SQL2000做高级搜索(或全文检索)
- C#中如何在客户端显示一个对话框???
- 在应用程序结束之前,垃圾回收器是不是一定会把废弃对象的内存全部回收。----请高手详细回答,多谢。
- 想实现类似进度条的东东,各位大哥都进来看一下,帮忙解一下
- 一个byte[16]数组,分别要写入二进制码,分段二进制码,BCD码,请问如何写,怎么转换?
- 基于RDP的远程桌面客户端的驱动重定向(磁盘映射)
- winform里怎么串行化控件??
- 急::Vs2005错误..确保已安装文件类型(.aspx)的应用程序-----
- 求.Net Remoting电子书
- asp.net中使用owc11问题
A class wrapper for the value type. This is strongly-typed, but still involves a heap allocation, and the you have to write the wrapper.
A struct wrapper that supports the concept of nullability. This is a good solution, but you have to write it yourself.
To make this easier, in VS 2005, we're introducing a new type named "Nullable", that looks something like this (it's actually more complex than this, but I want to keep the example simple):struct Nullable<T>{ public bool HasValue; public T Value;}
You can use this struct directly, but we've also added some shortcut syntax to make the resulting code much cleaner. The first is the introduction of a new syntax for declaring a nullable type. Rather than typing:Nullable<int> x = new Nullable<int>(125);
I can write:int? x = 125;
which is much simpler. Similarly, rather than needed to write a null test as:if (x.HasValue) {...}
you can use a familiar comparison to null:if (x != null) {...}
Finally, we have support to make writing expressions easier. If I wanted to add two nullable ints together and preserve null values, if I didn't have language support, I would need to write:Nullable<int> x = new Nullable<int>(125);Nullable<int> y = new Nullable<int>(33);Nullable<int> z = (x.HasValue && y.HasValue) ? new Nullable<int>(x.Value + y.Value) : Nullable<int>.NullValue;
At least I think that's what I'd have to write - it's complex enough that I'm not sure this code works. This is ugly enough that it makes using Nullable without compiler support a whole lot of work. With the compiler support, you write:int? x = 125;int? y = 33;int? z = x + y;
??:
The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand. A nullable type can contain a value, or it can be undefined.The ?? operator defines the default value to be returned when a nullable type is assigned to a non-nullable type.If you try to assign a nullable type to a non-nullable type without using the ?? operator,you will generate a compile-time error.If you use a cast, and the nullable type is currently undefined, an InvalidOperationException exception will be thrown.……………………for example// nullable_type_operator.csusing 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");
}
}
传入
private void SaveTreeViewExpandedState(TreeNodeCollection nodes, List<bool?> list)
这个方法两个参数
第一个是TreeNodeCollection
第2个是可以Null的list<bool>数组假如HttpContext.Current.Session[key + treeView.ID]是null
就传入一个
null的List <bool?>数组
就这个意思
没理解错吧?!The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand