default of c#

default of c#

 在泛型类和泛型方法中产生的一个问题是,在预先未知以下情况时,如何将默认值分配给参数化类型 T:

  • T 是引用类型还是值类型。
  • 如果 T 为值类型,则它是数值还是结构。

  给定参数化类型 T 的一个变量 t,只有当 T 为引用类型时,语句 t = null 才有效;只有当 T 为数值类型而不是结构时,语句 t = 0 才能正常使用。解决方案是使用default 关键字,此关键字对于引用类型会返回 null,对于数值类型会返回零对于结构,此关键字将返回初始化为零或 null 的每个结构成员,具体取决于这些结构是值类型还是引用类型。以下来自 GenericList<T> 类的示例显示了如何使用 default 关键字。

  

 1 public class GenericList<T>
 2 {
 3     private class Node
 4     {
 5         //...
 6
 7         public Node Next;
 8         public T Data;
 9     }
10
11     private Node head;
12
13     //...
14
15     public T GetNext()
16     {
17         T temp = default(T);
18
19         Node current = head;
20         if (current != null)
21         {
22             temp = current.Data;
23             current = current.Next;
24         }
25         return temp;
26     }
27 }

参考:http://msdn.microsoft.com/zh-cn/library/xwth0h0d(v=vs.90).aspx

时间: 2024-11-05 13:38:05

default of c#的相关文章

错误号:1364 错误信息:Field &#39;platId&#39; doesn&#39;t have a default value

1. 错误描述 错误号:1364 错误信息:Field 'platId' doesn't have a default value insert into `use`.`t_platform_scale` () values () 2.错误原因 由于在建表时,给platId一个not null限制,而且没有给默认值,在插入数据时未插入,导致报错 3.解决办法 (1)修改platId可以为null (2)插入数据时一定要插入platId 版权声明:本文为博主原创文章,未经博主允许不得转载. 错误号

pip 警告!The default format will switch to columns in the future

pip警告! DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning. pip升级到9.0.1后 查看pip.list 出现的警告

错误: No API token found for service account &quot;default&quot;,

[[email protected] pods]# kubectl create -f mysql.yaml Error from server (ServerTimeout): error when creating "mysql.yaml": No API token found for service account "default", retry after the token is automatically created and added to t

Java学习-050-AES256 之 java.security.InvalidKeyException: Illegal key size or default parameters 解决方法

在进行 Java AES 加密测试时,出现如下错误信息: java.security.InvalidKeyException: Illegal key size or default parameters at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1026) at javax.crypto.Cipher.implInit(Cipher.java:801) at javax.crypto.Cipher.chooseProvider(Cip

Implicit super constructor Object() is undefined for default constructor. Must define an explicit c

Eclipse错误 Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor 解决方案:把Java的类库加载进去,在工程上右键选择属性->JavaBuild Path的Libraries->Add Library选择JRE System Library->点击Next->选择Execution environment并选择

mysqldump 备份某张表 Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions,

[[email protected] ok]# mysqldump -uemove -h xx.xx.xx.xx -P9906 DBname t_name -p >2t_tname.sqlWarning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the

SQL DEFAULT 约束

SQL DEFAULT 约束 DEFAULT 约束用于向列中插入默认值. 如果没有规定其他的值,那么会将默认值添加到所有的新记录. SQL DEFAULT Constraint on CREATE TABLE 下面的 SQL 在 "Persons" 表创建时为 "City" 列创建 DEFAULT 约束: My SQL / SQL Server / Oracle / MS Access: CREATE TABLE Persons ( Id_P int NOT NUL

Android开发 default activity not found

新建的项目,今天打开的时候,发现无法编译了.编译按钮无法点击,必须edit configuration.并且报错 default activity not found. 解决: 少写了一个"/>",补全就对了...无语吧.. Donate:)

Java开发中经典的小实例-(swich(){case:参数break;default: break;})

import java.util.Scanner; public class Test6 { public static void main(String[] args) {        // TODO Auto-generated method stub                        Scanner input =new Scanner(System.in);                System.out.println("pleace input your sex:(

&quot;System Protection&quot; is disabled in Win10 default settings

We could find some important clue in Restore Point because "System Protection" of volume C is enabled in Windows default settings. Lots of data in "My Documents", "Desktop", and "Favorotes". Further more lots of Win