I have a public string, called tester, that I would like to use within my deletetask_Click event, how could this be used within the st.DeleteTask line?
public string tester {get;set;}
private void deletetask_Click(object sender, EventArgs e)
{
ScheduledTasks st = new ScheduledTasks(@"\\" + System.Environment.MachineName);
st.DeleteTask("tester");
}
删除引号:
st.DeleteTask(tester);
Unless I am misunderstanding your question, you can just try:
st.DeleteTask(tester); // no quotes around variable name
When you put quotes around it, you are essentially creating a new string which contains the text "tester"
. However, when you remove the quotes, C# interprets it as a reference to the tester
variable, which contains the string you already created.
您不能仅将变量测试器传递给方法st.DeleteTask吗?
You can just use it as is. In your code snippet, tester
is class-level, and can be used in any of the classes non-static methods.
private void deletetask_Click(object sender, EventArgs e)
{
ScheduledTasks st = new ScheduledTasks(@"\\" + System.Environment.MachineName);
st.DeleteTask(tester);
}
If tester is declared within the same class as that method, then simply like this:
private void deletetask_Click(object sender, EventArgs e)
{
ScheduledTasks st = new ScheduledTasks(@"\\" + System.Environment.MachineName);
st.DeleteTask(tester);
}
If it's not, where is it declared?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.