473,782 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList help...

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(in t index,int value)
{

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

this.Session["QuestionHierar chy"] = 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

Nov 16 '05 #1
1 1661
Irfan Akram <Ir********@dis cussions.micros oft.com> wrote:
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(in t index,int value)
{

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

this.Session["QuestionHierar chy"] = 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.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3907
by: Stephen | last post by:
I have got an event below to remove items from an arraylist and then to rebind the arraylist to the datagrid subsequently deleting the appropriate row. My problem is that my code makes sense and I think my logic seems fine but when I click the button on my datagrid nothing seems to happen. Have you any idea where Im going wrong. Was thinking it might have something to do with my page load/ postback but not really sure. Can someone please...
3
1470
by: Stephen | last post by:
I've been working on some code which will hopefully allow me to transfer the contents of an arraylist on one page over to another page. The Arraylist is held in the viewstate object as it is populated on the on-click event of a button. Im trying to move to another page and carry over the items in my arraylist and write them to the page. The code ive been trying to work with to achieve is detailed below. I am getting an error and im not...
2
7811
by: Stephen | last post by:
I am trying to delete a row in a datagrid on the onclick of a asp:ButtonColumn. The datagrid is created from the items in an arraylist so what im trying to do is remove the item from the array and then rebind the datagrid. Below is the code I have to delete the items from the arraylist but nothing seems to happen when I run this code. Does any one have any idea where Im going wrong. Thanks for any help you can give me. private void...
3
2859
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a datagrid. I am using the viewstate object to store the Arraylist items on the page on postback. My PROBLEM is that I need to redirect the user to a new aspx page and on this new page i need to be able to access the items in my arraylist. Is this...
9
1413
by: Leon | last post by:
I have a webform in which when the user press generate button the form generate six unique ramdon numbers, the user can also type these six numbers in manually in any order. however, the user can also press a post button that post these six numbers into the database. My problem is that these six numbers need to be posted to the database from less to greatest, and all of my code is within the business tier class not the code behind class. ...
7
1797
by: Dave | last post by:
Hi all, I have... using System.Collections; namespace MyApp.Templates { public class MyPage : System.Web.UI.Page { ArrayList MyArray = new ArrayList();
6
5388
by: gane kol | last post by:
Hi, I have a code that creates a datatable from an arraylist, but i am getting an error in casting in for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow = dtLCPack.NewRow(); int intColCount = dtLCPack.Columns.Count; ArrayList arrlRow = (ArrayList)alLCPlist; <== Specified cast
6
1463
by: GrandpaB | last post by:
While writing this plea for help, I think I solved my dilemma, but I don't know why the problem solving statement is necessary. The inspiration for the statement came from an undocumented VB example I found on the web. I would be most appreciative if someone could explain why this statement is necessary and what does it do: MyArt = New Art
18
4749
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class instance. However, the 'indexof' is never calling my overloaded, overrides Equals method. Here is the...
6
3142
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it to the client. Before adding data to the arraylist, I check if the depth of the arraylist is longer than iMaxQueueDepth, and if it is, I clear the arraylist. Is it possible that while I am clearing the arraylist, the ThreadMain at the same time...
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.