C#数据没初始化,使用会报错,可以初始化null

protected void Page_Load(object sender, EventArgs e)
{

  string[] A;

  

  if (B== 0)
  {

    A = new string[] {1,2,3,4,5 };

  }

  funD(A);

}

这样会在funD(A);报错,使用了未赋值的局部变量“A"

要这样

protected void Page_Load(object sender, EventArgs e)
{

  string[] A = null;

  

  if (B== 0) 
  {

    A = new string[] {1,2,3,4,5 };

  }

  funD(A);

}

原文地址:https://www.cnblogs.com/suxiaBlogs/p/7243203.html