473,419 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Get index of arraylist classed object

How can I update the rank object inside the arraylist based on its
index?

ContainerKeywords k = new ContainerKeywords();
int rank = 0;
if (ArItems.Contains(sItem)==false) // if did not find
{
k.item_id = sItem.ToString();
k.rank = rank;
ArItems.Add(k);
}else{ // if found
rank++
// I want to update rank here based on the arraylist position that
is found
}

I don't have any clue of how to do it.

Thank you

Rod

Nov 19 '05 #1
9 1566
"Rodusa" <rc**********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
How can I update the rank object inside the arraylist based on its
index?

ContainerKeywords k = new ContainerKeywords();
int rank = 0;
if (ArItems.Contains(sItem)==false) // if did not find
{
k.item_id = sItem.ToString();
k.rank = rank;
ArItems.Add(k);
}else{ // if found
rank++
// I want to update rank here based on the arraylist position that
is found
}

I don't have any clue of how to do it.


The answer is in one of the member methods of the ArrayList class. Do you
have access to that documentation?

John Saunders
Nov 19 '05 #2
Yes I do. I tried
int idx = ArItems.IndexOf(sItem);
before contains, but it always returns -1. Seems like indexof is not
looking inside the typed object, and therefore is always returning -1.

I need help. I don't know where else to look for info.

ContainerKeywords k = new ContainerKeywords();
int rank = 0;
if (ArItems.Contains(sItem)==false) // if did not find
{
k.item_id = sItem.ToString();
k.rank = rank;
ArItems.Add(k);
}else{ // if found
rank++
// I want to update rank here based on the arraylist position that
is found
}

I don't have any clue of how to do it.
The answer is in one of the member methods of the ArrayList class. Do

you have access to that documentation?

John Saunders


Nov 19 '05 #3
"Rodusa" <rc**********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Yes I do. I tried
int idx = ArItems.IndexOf(sItem);
before contains, but it always returns -1. Seems like indexof is not
looking inside the typed object, and therefore is always returning -1.


Thanks for the detail. It all helps.

What happens if you call IndexOf after the Contains returns true? It should
return an index.

Unless Contains never returns true?

John Saunders
Nov 19 '05 #4
Thank you. I will look at your suggestion and check if contains returns
true.

Rod

Nov 19 '05 #5
You are right, contains is always returning false. What can I do?

Nov 19 '05 #6
Do I need to cast sItem?
Something like this:
string sItem = ((ContainerKeywords) ArItems[1]).item_id.ToString();

Nov 19 '05 #7
"Rodusa" <rc**********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Do I need to cast sItem?
Something like this:
string sItem = ((ContainerKeywords) ArItems[1]).item_id.ToString();


If I were you, I'd get into the debugger and start looking at the arraylist.

Otherwise, you can start using Response.Write sorts of things, for instance
to check the number of items in the list, to go through the list and display
each item, etc.

John Saunders
Nov 19 '05 #8
Thank you so very much John,

It looks like that contains is looking at a string instead of looking
at the class of ArItems

Below, a little bit of more information
public class ContainerKeywords
{
private int _rank;
public int rank
{
get { return _rank; }
set { _rank = value; }
}

private string _item_id;
public string item_id
{
get { return _item_id; }
set { _item_id = value; }
}
}

Is there any way to specify in the contains method which column for the
search to happen?
ContainerKeywords k = new ContainerKeywords();
int rank = 0;
if (ArItems.Contains(sItem)==false) // if did not find
{

k.item_id = sItem.ToString();
k.rank = rank;
ArItems.Add(k);
Rod

Nov 19 '05 #9
"Rodusa" <rc**********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Thank you so very much John,

It looks like that contains is looking at a string instead of looking
at the class of ArItems

Below, a little bit of more information
public class ContainerKeywords
{
private int _rank;
public int rank
{
get { return _rank; }
set { _rank = value; }
}

private string _item_id;
public string item_id
{
get { return _item_id; }
set { _item_id = value; }
}
}

Is there any way to specify in the contains method which column for the
search to happen?
ContainerKeywords k = new ContainerKeywords();
int rank = 0;
if (ArItems.Contains(sItem)==false) // if did not find
{

k.item_id = sItem.ToString();
k.rank = rank;
ArItems.Add(k);


I'm really not seeing what your code is meant to do. What is "sItem"?

John Saunders
Nov 19 '05 #10

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

Similar topics

4
by: vijay | last post by:
I have a doubt with size of classed with virtual functions I have declared A,A1,A2 ,B , C, D some classes with no varaibles but a vitual function each, The size of A is as expected 4 bytes with...
9
by: Steffen Laser | last post by:
Hi group, I have a problem that I already have posted to the german C# newsgroup. Since nobody could help me there, I'd like to try it here again: I set the selected item of a combobox like...
2
by: kscdavefl | last post by:
When I run the following code: private void applicationPermissionGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType ==...
3
by: Bradley | last post by:
Hi I have an ArrayList populated with some objects. Each object has some properties, and I'd like to find the ArrayList's index where the object's "SerialNumber" property is equal to a certain...
4
by: Fir5tSight | last post by:
Hi, I declare PageObjectsArray1 and PageObjectsArray2 as ArrayList. Each element in the array is a Page object. Now I want to compare every pair of Page objects of the same index in the two...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
by: jivesam | last post by:
I have an application that look up user's firstname, lastname, email from Active Directory and dispay any open ticket associated with the user. The program runs correctly for all US users but it...
6
by: thanigaimani83 | last post by:
Hi guys. i can explain for my doubt with example.see.my table have multiple type of employee details like as Mangemment,Programmer,Designers,Accountants,ContractEmployees.Each type of department...
0
by: biswal.srikant | last post by:
I've been trying to correct this error for approx 2 days and am having no luck. In a page's button clickevent , i want to bind a infragistic grid according to two dropdown value. At the first...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.