【发布时间】:2012-01-30 07:34:11
【问题描述】:
我写了这个,我得到了以下错误。有什么简单的方法可以让变量互相看到吗?
警告 1 变量“notepad_running”已赋值,但从未使用过它的值。
错误 2 当前上下文中不存在名称“notepad_running”。
错误 3 当前上下文中不存在名称“notepad_list”。
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;
}
}
}
【问题讨论】:
-
您知道您可以通过codereview.SE 审查您的代码吗?您的代码存在一些设计问题,您可以在那里收集反馈。
标签: c# class variables methods