Solved

global variables

Posted on 2008-10-27
4
1,686 Views
Last Modified: 2013-12-17
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
Comment
Question by:amillyard
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:philipjonathan
ID: 22818405
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
 

Author Comment

by:amillyard
ID: 22825709
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
 
LVL 18

Accepted Solution

by:
philipjonathan earned 500 total points
ID: 22827796
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
 

Author Closing Comment

by:amillyard
ID: 31510582
many thanks :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now