gpt4 book ai didi

VS2005 中的 C# : what do the following types default to in C#?

转载 作者:太空狗 更新时间:2023-10-30 00:17:15 26 4
gpt4 key购买 nike

对于VS2005中的C#,下面几种类型的变量,如果只是简单声明,不赋值,它们的值是多少? IE。它们的默认值是多少?

int
bool
string
char
enum

最佳答案

这是您提到的每种类型的默认值。

int = 0  
bool = false
string = null
char = '\0'
enum = 0 //behind the scenes enum is int

向前推进,如果您希望在运行时捕获任何类型的默认值,那么您可以在 C# 中使用 default 语句并简单地调用它如下。

//This will print 0 on screen.
Console.WriteLine(default(int));

通常,这在泛型中用于标识泛型类型参数的默认值,其中类型仅在运行时已知。

关于VS2005 中的 C# : what do the following types default to in C#?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3146525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com