Q:

when to use shared variables

I have built a class which is instantiated many times in a list using vb.net. I want to persist an ID across all instantiations of my class. It's a list of questions which will all have one questionnaire ID. So I can do this whilst assigning the id to each question in the list. Ideally I would like to just assign the ID once and have it available in all the list objects.
So here is my shared member of a class along with property procedure for accessibilty.
 Public Class Questions
     Private Shared _questionnaireUID As Integer

    Public Shared Property QuestionnaireUID() As Integer
    Get
        Return _questionnaireUid
    End Get
    Set(ByVal value As Integer)
        _questionnaireUid = value
    End Set
    End Property
End Class

I started to use a vb.net shared class level variable and assigned through a property procedure. This seemed like the right approach, although now I have built it I can see that the shared variable is accessible throughout the entire application.
So like this for instantiation and assignment.
    Questions.QuestionnaireUID = CInt(questionnaireUID)

I dont even need to instantiate the class. So I now just have a global variable. to get around this I would use a class level variable instead of. I wondered if there is another way to just make the variable shared across the class and it's instantiated objects without assigning to each object and without making it available across the entire application. Is there a step I am missing.
Thanks for any advice.

A:

I am C# but that is not how I would go about it.
Have a class for the questionnaire
public class Questionnaire
{
   public Int ID { get; private set; }
   public List<Question> Questions  { get; set; }
}

