为什么在C#中我们需要初始化基本类型变量? [英] why in c# we need to initialize primitive type variable?
本文介绍了为什么在C#中我们需要初始化基本类型变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么在C#中我们需要初始化基本类型变量-
why in c# we need to initialize primitive type variable --
static void Main(string[] args)
{
int a;
Console.WriteLine(a);
}
引发编译时错误...
推荐答案
为防止潜在的编码错误,C#将不允许您使用任何局部变量,除非编译器可以证明它已被初始化.
In order to prevent potential coding mistakes, C# will not allow you to use any local variable until the compiler can prove that it has been initialized.
这篇关于为什么在C#中我们需要初始化基本类型变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文