Tôi đã viết điều này và tôi nhận được các lỗi sau. Có cách nào đơn giản để làm cho các biến nhìn thấy nhau không?Chia sẻ các biến giữa các lớp và phương thức
Cảnh báo 1 Biến 'notepad_running' được chỉ định nhưng giá trị của nó không bao giờ được sử dụng.
Lỗi 2 Tên 'notepad_running' không tồn tại trong ngữ cảnh hiện tại.
Lỗi 3 Tên 'notepad_list' không tồn tại trong ngữ cảnh hiện tại.
public class notepad_check_class
{
public static void notepad_check()
{
Process [] notepad_list = Process.GetProcessesByName("notepad");
if (notepad_list.Length > 0)
{
int notepad_running = 1;
}
}
}
public class kill_notepad_class
{
public static void kill_notepad()
{
notepad_check_class.notepad_check();
if (notepad_running = 1)
{
if (MessageBox.Show("Are you sure you want to kill all notepad processes?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
foreach (Process notepad_process in notepad_list)
{
notepad_process.Kill();
}
return;
}
else
{
MessageBox.Show("Cannot find any running process of notepad.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
bạn có biết bạn có thể nhận mã của bạn xem xét tại [codereview. SE] (http://codereview.stackexchange.com)? Có một số vấn đề về thiết kế với mã của bạn mà bạn có thể thu thập phản hồi ở đó. – Adam