0

I am hoping to create a dictionary like this:

Dictionary<string, Variable> dict = new Dictionary<string, Variable>

In this thread How do I name variables dynamically in C#? the following code example was voted up and accepted as the answer to the question:

var vartable = new Dictionary<string, Variable>();
vartable[strLine] = new Variable(input);

However, when I try to do the same thing I get this error Message:

The type or namespace name 'Variable' could not be found (are you missing a using directive or an assembly reference?)

I have been unable to find a namespace that fixes this. Any advice is appreciated.

Regards.

Community
  • 1
  • 1
Kevin
  • 1,252
  • 6
  • 32
  • 50
  • What is `Variable`? You're referencing it like a type. The error indicates that you don't have a `using` statement that imports that type for use. You also may have to add a project reference to whatever library contains `Variable`. – Justin Skiles Aug 17 '12 at 14:59
  • Look in the original question you reference. He states that he has already created his own `Variable` class. http://cl.ly/image/3F012q2P1L3V – Mark Rucker Aug 17 '12 at 15:02
  • Variable is the name of the object that you want a dynamic name for. – VoidStar Aug 17 '12 at 15:03
  • @MarkRucker: [Smacks forehead] You're right. I read the question heading and the answer and overlooked the implementation details. I was rushing. Thanks for pointing that out. – Kevin Aug 17 '12 at 15:10
  • No problem. We all get a little spacey sometimes. :) – Mark Rucker Aug 17 '12 at 17:27

2 Answers2

2

Variable is meant to be your own class, so you have to define it first.

twoflower
  • 6,788
  • 2
  • 33
  • 44
2

There's no type called Variable. It's just an example type name.

sloth
  • 99,095
  • 21
  • 171
  • 219