Solved

global variables

Posted on 2008-10-27
4
1,685 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

12 Experts available now in Live!

Get 1:1 Help Now