How can I access the variable line in the following subscriber method from another method within the same class:
private void portdatareceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string line = port.ReadExisting();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Make it a field in the class. You cannot access local variables in methods.
After all, classes are data containers and methods act on that data. local variables are just helpers to that end. If they are needed as state in the class, then make them a field.