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)
        {
            
            collBlock.Clear();
            try
            {
                for (int i = 0; i < nNumOfBlock; i++)
                {
                    aBlock = new DataBlock();
                    aBlock.Init(aReader);
                    collBlock.Add(aBlock.GetName(), aBlock);
                }
                return 0;
            }
            catch
            {
                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;
        }

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.

Comments
Repeating what the person above you said doesn't add anything to the conversation.

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.

This question has already been answered. Start a new discussion instead.