码迷,mamicode.com
首页 > 其他好文 > 详细

[keyword] 默认关系字default(T) 输出结果汇总

时间:2019-09-12 09:38:34      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:http   method   ble   test   time   double   new   pre   ref   

[keyword] 默认关系字default(T) 输出结果汇总


default (C# Reference)

default Keyword in Generic Code (C# Programming Guide)

   1:          [TestMethod()]
   2:          public void DefaultTest()
   3:          {            
   4:              Assert.IsNull(default(VW_DW_EMP));
   5:  ?
   6:              Assert.IsNull(default(string));
   7:  ?
   8:              Assert.AreEqual(0, default(byte));
   9:  ?
  10:              Assert.AreEqual(0, default(int));
  11:  ?
  12:              Assert.AreEqual(0, default(long));
  13:  ?
  14:              Assert.AreEqual(0, default(float));
  15:              
  16:              Assert.AreEqual(0, default(double));
  17:  ?
  18:              Assert.AreEqual(0, default(decimal));
  19:              
  20:              Assert.AreEqual(0, default(char));
  21:  ?
  22:              Assert.AreEqual(false, default(bool));
  23:  ?
  24:              Assert.AreEqual(DateTime.MinValue, default(DateTime));
  25:  ?
  26:              Assert.AreEqual(ENUM_LAB.NONE, default(ENUM_LAB));
  27:  ?
  28:              Assert.AreEqual(new STRUCT_LAB(), default(STRUCT_LAB));
  29:  ?
  30:              Assert.IsNull(default(int?));
  31:          }
  32:  ?
  33:          enum ENUM_LAB
  34:          {
  35:              NONE, UT01, UT02
  36:          }
  37:  ?
  38:          struct STRUCT_LAB
  39:          {
  40:              string UT;
  41:          }

同理可证 LINQ :

   1:          [TestMethod()]
   2:          public void LinqDefaultTest()
   3:          {
   4:              int[] intArray = { };
   5:              Assert.AreEqual(0, intArray.FirstOrDefault());
   6:  ?
   7:              string[] strArray = { };
   8:              Assert.IsNull(strArray.FirstOrDefault());
   9:  ?
  10:              VW_DW_EMP[] empArray = { };
  11:              Assert.IsNull(empArray.FirstOrDefault());
  12:  ?
  13:              bool[] boolArray = { };
  14:              Assert.AreEqual(false, boolArray.FirstOrDefault());
  15:  ?
  16:              bool?[] nullableBoolArray = { };
  17:              Assert.IsNull(nullableBoolArray.FirstOrDefault());
  18:  ?
  19:              DateTime[] dateTimeArray = { };
  20:              Assert.AreEqual(DateTime.MinValue, dateTimeArray.FirstOrDefault());
  21:          }

原文:大专栏  [keyword] 默认关系字default(T) 输出结果汇总


[keyword] 默认关系字default(T) 输出结果汇总

标签:http   method   ble   test   time   double   new   pre   ref   

原文地址:https://www.cnblogs.com/petewell/p/11509964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!