摘要: ?? 运算符定义在将可空类型分配给非可空类型时返回的默认值。int? c = null;//若 c 为 null,则 d 为 -1,否则把 c 值赋予 dint d = c ?? -1;类型名称后加问号,如:int? i = null;double? d = null;bool? b = null;可指定可为 null 的 int、double、bool 等类型。或者用 Nullable,和上述方... 阅读全文
posted @ 2009-07-16 15:40 肚肚 阅读(243) 评论(0) 推荐(0)
摘要: 判断字符串的长度是否为零可以用 if (str.Length == 0),但如果 str 可能是 null 引用(Basic 语言中为 Nothing),则直接这样用会产生异常,所以需要先判断是否为 null。方法一、和 null 比较if (str == null || str.Length == 0)在 C++、C# 中,这里,如果 str == null 为 true,则不会继续判断 str... 阅读全文
posted @ 2009-07-16 15:22 肚肚 阅读(768) 评论(0) 推荐(0)
摘要: http://www.cftea.com/docs/asp.net/c-sharp/ 阅读全文
posted @ 2009-07-16 15:19 肚肚 阅读(192) 评论(0) 推荐(0)
摘要: 以下是使用枚举时几条好的建议。优先考虑使用枚举,而不是类的静态常量比如:public static class Day{ public static int Sun = 1; public static int Mon = 2; public static int Tue = 3; //...}应该使用如下的枚举:enum Day { Sun = 1, Mon, Tue, Wed, Thu, Fr... 阅读全文
posted @ 2009-07-16 15:17 肚肚 阅读(217) 评论(0) 推荐(0)
摘要: C# 中结构与类的区别目录类与结构的实例比较 类与结构的差别 如何选择结构还是类类与结构的示例比较结构示例public struct Person{ string Name; int height; int weight public bool overWeight() { //implement something }}类示例public class TestTime{ int hours; ... 阅读全文
posted @ 2009-07-16 14:55 肚肚 阅读(303) 评论(0) 推荐(0)