gpt4 book ai didi

c# - DateTime 变量超出范围

转载 作者:太空宇宙 更新时间:2023-11-03 19:10:29 28 4
gpt4 key购买 nike

我在代码隐藏中得到了这段代码:

while (DT1.Read())
{
//Read the record into an "array", so you can find the SProc and View names
int MyRptID = Convert.ToInt32(DT1[0]);
string MyRptName = DT1[1].ToString();
string MyRptSproc = DT1[2].ToString();
string MySQLView = DT1[3].ToString();

if (string.IsNullOrWhiteSpace(this.txtStartDate.Text))
{
DateTime MyStDate = Convert.ToDateTime(this.txtStartDate.Text);
}

if (MyStDate != null)
{
cmd2.Parameters.Add("@StDate", SqlDbType.Date).Value = txtStartDate.Text;
}

MyStDate 带有红色下划线,当我将鼠标悬停在它上面时,我会看到一个弹出窗口,显示“名称‘MyStDate’在当前上下文中不存在。”谁能告诉我这是为什么?它与它在括号之外的事实有关吗?如果是这样,我怎样才能让它发挥作用?

最佳答案

MyStDate 的范围是 if 条件。变量在其范围之外是不可见的,因此您需要在 if 之外声明 MyStDate

关于c# - DateTime 变量超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20980805/

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