[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1692
  • Last Modified:

global variables

the attached code snippet is how I setup a globally accessible string.

below, how I do the same for an array of 50 strings as follows:  (to be globally accessible)

string[] inputData = new string[50];
private static string inputText;
 
        public static string _inputText
        {
            get { return inputText; }
            set { inputText = value; }
        }

Open in new window

0
amillyard
Asked:
amillyard
  • 2
  • 2
1 Solution
 
philipjonathanCommented:
private static string[] inputData = new string[50];
 
        public static string[] InputData
        {
            get { return inputData; }
            set { inputData = value; }
        }

To access an element:
ClassName.InputData[index] = "blah...";
0
 
amillyardAuthor Commented:
the example is working fine.

I am setting a couple of related vriables, 1. int   2. bool

is supplied code snippet the way to do this -- is forming a struct a better way forward?  if so, how?
private static string[] inputData = new string[wordParseMaxArray];
 
        public static string[] _inputData
        {
            get { return inputData; }
            set { inputData = value; }
        }
 
        private static bool[] inputDataRecognised = new bool[wordParseMaxArray];
 
        public static bool[] _inputDataRecognised
        {
            get { return inputDataRecognised; }
            set { inputDataRecognised = value; }
        }

Open in new window

0
 
philipjonathanCommented:
Do you mean each element has string, int and bool properties? Then yes structure is a better way. It keeps related pieces of information together.

public struct InputDataStruct
{
    public string Data;
    public bool isRecognised;
}

private static InputDataStruct[] inputData;

public static InputDataStruct[] _inputData
{
    get
    {
        return inputData;
    }
}

When initialising the structure:
inputData = new InputDataStruct[wordParseMaxArray];
for (int i = 0; i < wordParseMaxArray; i++)
{
    inputData[i] = new InputDataStruct();
}
0
 
amillyardAuthor Commented:
many thanks :-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now