所以我剛剛開始學習C#,並且遇到了一個錯誤消息,說Form5「是一個變量,但用於類型」。我已經顯示了有錯誤的代碼頁,但如果你想看看更大的圖片,這裏是我的github回購(我是gihub的完全noob,所以如果有任何錯誤或完全錯誤,我很抱歉! :https://github.com/ValorZard/ChocobombVisual Studio認爲winform是一個變量
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 animal_years
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
/*
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
*/
Form Form1 = new Form1();
Form1.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form Form3 = new Form3();
Form3.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Form Form2 = new Form2();
Form2.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Form Form4 = new Form4();
Form4.Show();
}
private void button5_Click(object sender, EventArgs e)
{
Form Form5 = new Form5();
Form5.Show();
}
}
}
你的'Form5()'的構造函數在哪裏? –
不要聲明與聲明該類相同名稱的變量。 'Form5'是類名,你也是用相同的名稱聲明變量 –
是否有一個原因,你需要命名變量的類名相同?如果你想避免使用類名作爲變量名(它不能解決你的問題,但可能會揭示這個問題),它會讓你的代碼更易於調試。 –