-4

I would like to ask how can I make below structured data globally available to all classes:

class clsData1
{
   int Num1;
   int Num2;
   string Str1;
}

class clsData2
{ 
   int Num3;
   int Num4;
   string Str2;
}

class Main
{
   clsData1 clsData1A;
   clsData2 clsData2A;
}

I guess solution is with singleton, but example would be helpful.

Aditionally I would like that this data structure works as global over all classes.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bejingaf
  • 1
  • 1

2 Answers2

0

As @Willem Van Onsem mentions in comments a SingleTon has nothing to do with wheather a class is accessable within the whole solution or not. However it only guarantees that for the class only one single instance can be created. So the following code usually doesn´t work for a singleton-class:

var myInstance = new MySingleton();

This can be achieved by defining a private constructor for MySingleton-class. Thus the constructor cannot be called from outside the class.

What you want to do is making your classes public which will allow you to access it anywhere. You may see access-modifiers for more information on public.

MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
  • I would like to have only one instance of this data structure avaiable in whole app in all classes, like global variables. – Bejingaf Jan 12 '16 at 09:00
0

maybe I was not clear enough.

I would like that this data struct is working as global variable, avaiable in all classes, fo

Bejingaf
  • 1
  • 1