alternative to dynamic variable name in C#

c#, global-variables, instance-variables

Solution

Why not use something like a dictionary? e.g.:

var stocks = new Dictionary<string, double>();
stocks.Add("appl", 1234.56);
Print(stocks["appl"]);

You can dynamically add ticker names and values to it as needed, give you lookup by ticker, and a whole host of other useful features. Any reason you want individual variables as opposed to a collection?

Problem

I am writing my custom indicators within NinjaTrader which has a scripting language built on C#. I would like to share data between different stock charts, but there is no inherent way to do so. Each indicator inherits from an Indicator class and of course each chart runs a unique instance of any indicators applied. For example, I would like to be able to 'send' the current price of IBM to a chart of AAPL. Conceptually, on the 'sending' chart I need to be able to do something like: static double IBM = 190.72; however, when the user changes the chart ticker from IBM to DELL for example, I now need something like: static double DELL = 9.25; On my 'receiving' chart I would like to be able to do something like Print(DELL); So my tendency is to want to have a variable name that is assigned dynamically based upon the ticker symbol that the user has chosen for the chart, however I know this isn't possible in C#. So what is a good alternative approach to storing and retrieving data that needs to be indexed by ticker name when there is a practically unbounded set of potential ticker values?

Original source