global variables

Posted on 2008-10-27
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

Question by:amillyard
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 18

Expert Comment

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...";

Author Comment

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

LVL 18

Accepted Solution

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
        return inputData;

When initialising the structure:
inputData = new InputDataStruct[wordParseMaxArray];
for (int i = 0; i < wordParseMaxArray; i++)
    inputData[i] = new InputDataStruct();

Author Closing Comment

ID: 31510582
many thanks :-)

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio npm 1 38
reading excel file in .net 2 44
PowerShell:  foreach where object notmatch? 17 70
.NET XML to Dictionary - XML has repeating node names 8 25
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

739 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