Variable of class

0
0

Hi, I have a question: if I declare a class variable in a Form, for example string cVar = “value”, will it be reassigned every time the Form is opened or will it become a session variable?

Example:

public partial class Test : Form
{

string cVar = “value”;//Is this destroyed every time the Form Test is closed?
public Test ()
{
InitializeComponent();
}

}

Thank you

  • You must to post comments
0
0

Hi Francesco,

The variable is going to be assigned whenever you create a new form, it will not become a session variable!

To use session variables, please consider using Application.Session[“cVar”] = “value”, or, for a more advanced implementation, please consider looking at SessionReference .

Best Regards,
Alaa

 

  • Francesco Leo
    Thanks, that’s exactly what I expected. I already use session variables and I needed confirmation that class variables are, in fact, linked to the class and therefore are created again every time a Form is opened. For public static variables, however, the discussion is different, from what I understand.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.