ArrayList help...

G

Guest

Dear Friends,

I'll be glad if you guys could help out. I am currently doing a web project
in asp.net using c#. An ArrayList object in my code contains element records
containing 3 fields. In a particular portion of the code, I am trying to edit
my ArrayList object, i.e. edit a particular field in the list, but am unable
to do that succesfully. To illustrate my point further please see the code
below: -


private void EditQuestion(int index,int value)
{

//Edit the required Question.
ArrayList qh = (ArrayList)this.Session["QuestionHierarchy"];
if (qh != null)
{
((QInfo)qh[index]).ChildElements = value;
}

this.Session["QuestionHierarchy"] = qh;

}

where the Array list consists of item of type ContolInfo defined like this: -

private struct QInfo
{
public string ID;
public int ChildElements;
public int Parent;
}


I keep getting this compilation error..at the following line of code..given
above..

The left-hand side of an assignment must be a variable, property or indexer

-----> ((QInfo)qh[index]).ChildElements = value;


You might find this error trivial, but am stuck on this for quite a while.
Please help me out...will appreciate it..will wait for a useful reponse...

Many Thanks,

Irfan
 
J

Jon Skeet [C# MVP]

Irfan Akram said:
I'll be glad if you guys could help out. I am currently doing a web project
in asp.net using c#. An ArrayList object in my code contains element records
containing 3 fields. In a particular portion of the code, I am trying to edit
my ArrayList object, i.e. edit a particular field in the list, but am unable
to do that succesfully. To illustrate my point further please see the code
below: -


private void EditQuestion(int index,int value)
{

//Edit the required Question.
ArrayList qh = (ArrayList)this.Session["QuestionHierarchy"];
if (qh != null)
{
((QInfo)qh[index]).ChildElements = value;
}

this.Session["QuestionHierarchy"] = qh;

}

where the Array list consists of item of type ContolInfo defined like this: -

private struct QInfo
{
public string ID;
public int ChildElements;
public int Parent;
}


I keep getting this compilation error..at the following line of code..given
above..

The left-hand side of an assignment must be a variable, property or indexer

The problem is that you're using a struct rather than a class for
QInfo. Even if the code compiled, it wouldn't do what you wanted to -
the change wouldn't "take".

Change QInfo to a class and all should be well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top