Reputation: 25
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");
}
Upvotes: 0
Views: 112
Reputation: 9936
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?
Upvotes: 0
Reputation: 7096
Couldn't you just pass the variable tester to the method st.DeleteTask?
Upvotes: 2
Reputation: 5843
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.
Upvotes: 3
Reputation: 25684
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);
}
Upvotes: 0