2
나는 다음과 같은 오류를 받고 있어요 :"x는 현재 컨텍스트에 존재하지 않습니다"라는 이유는 무엇입니까?
Error 1 The name 'myList' does not exist in the current context
코드는 다음과 같습니다 :
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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
List<string> myList = new List<string>();
myList.Add("Dave");
myList.Add("Sam");
myList.Add("Gareth");
}
private void button1_Click(object sender, EventArgs e)
{
foreach (string item in myList)
{
listView1.Items.Add(item);
}
}
}
}
그것은 매우 간단한 예입니다 및 실제 응용 프로그램이 더 우리를 클래스의 밖으로 만들 것입니다,하지만 난 돈 왜 button1_click 이벤트 핸들러가 배열 목록을 볼 수 없는지 이해하지 못합니다.
'listView1'목록의 선언은 어디에 있습니까? – superpuccio
@superpuccio - listView1 목록은 내가 폼에 드래그 한 컨트롤입니다. 그것을 선언해야합니까? – Ows