I'm using Visual C# Express 2010, on Windows XP SP3.

I took pain to define the var collBlock in the class directly, however, when I try to use it, it works once and then NOT.

Google searched all and tried a lot of solution. Error stil comes up.
The code below is partial, don't count the '{}', they are correct (VS2010 autocorrect won't allow even the most indifferent mistyping)

public class DMSecDoc
	//...some declares...
	private Hashtable collBlock = new Hashtable();

	// this works...
	private int ReadAllBlocks(BinaryReader aReader, Int32 nNumOfBlock)
                for (int i = 0; i < nNumOfBlock; i++)
                    aBlock = new DataBlock();
                    collBlock.Add(aBlock.GetName(), aBlock);
                return 0;
                return 99;
	// this one does not. What gives ? =============
	private string[] GetThatDataBlock(String name)
            String[] arrData = null;

            //The name 'collBlock' does not exist in the current context
            DataBlock aBlock = (DataBlock)collBlock(name);

            arrData = aBlock.GetData();
            return arrData;

Recommended Answers

All 3 Replies

In line 33 you are using collBlock as a method, not an object, and it can't find any method named collBlock. What you should have is this:

DataBlock aBlock = (DataBlock)collBlock[name];  // square brackets

The element 'collBlock' exists alright in the current context, but it does not exists in the context you are using it.

try DataBlock aBlock = (DataBlock)collBlock[name];
where 'name' is referring to an existing key.

commented: Repeating what the person above you said doesn't add anything to the conversation. -1

Aaaaaeeeaargh...don't I feel stoopid.

I tried everything BUT the square bracket thing.
And that fixed it.

And I got a new definition for context (as in "context you are using it".)

Thanks a million, guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.