使用未分配的局部变量';表';。C#
因此,在调试代码时,我一直使用未分配的局部变量“table”error。我想做一个乘法表 下面是我的代码的外观使用未分配的局部变量';表';。C#,c#,C#,因此,在调试代码时,我一直使用未分配的局部变量“table”error。我想做一个乘法表 下面是我的代码的外观 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using Sy
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Multiplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDisplayTable_Click(object sender, EventArgs e)
{
int table;
int result;
for (int i = 1; i < 13; i++) {
result = table * i;
lstTable.Items.Add(result);
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void LstTable_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void txtTable_TextChanged(object sender, EventArgs e)
{
}
}
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
名称空间乘法
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
私有void btnDisplayTable_单击(对象发送方,事件参数e)
{
int表;
int结果;
对于(int i=1;i<13;i++){
结果=表*i;
表1.Items.Add(结果);
}
}
私有void btnExit\u单击(对象发送者,事件参数e)
{
这个。关闭();
}
私有void lstable_SelectedIndexChanged(对象发送方,事件参数e)
{
}
私有void txtTable_TextChanged(对象发送方,事件参数e)
{
}
}
}
任何帮助和解释都将不胜感激。初始化
表
变量
int table = 0;
您从未为
表变量赋值。之后您会执行table*i
,但它无法计算,因为table
没有值