Working with lists and adding elements - list

in C# if I declare a new list say, myList, can I add items to that list later at a specific index location like this, myList[2] = 42. And can I then write over that index location again without first deleting it by doing myList[2] = 28?

No, it will give you ArgumentOutOfRangeException

It sounds like an array would be a better choice.

Related

How to retrive assigned smarty template in prestashop?

Ok, so I have some smarty variables assigned on the checkout page in my shop. Problem is that when I want to use them -for example
{$address_collection.firstname}
I get an undefined index notice. I am certainly doing something wrong, but what?
on your screenshot $address_collection is array of objects, so to access to array element you need to use key, like $address_collection[124] and this element will contains address object,
where to get first name:
{$address_collection[124]->firstname}
If in smarty you want to access the array then you have to mention key of the array then you can use the values.If in your tpl file you want to print the array which you assigned then you have to write like
{var_dump($address_collection)}
Where $address_collection is the variable which from which you assigned values.
Now for access the values in your tpl file you have to mention key like:
{$address_collection['key_name']}
I hope it would help you.

Add to list within document MongoDB

I have a database where I store player names that belong to people who have certain items.
The items have and IDs, and subIDs.
The way I am currently storing everything is:
Each ID has its own collection
Within the collection there is a document for each subID.
The document for each subID is layed out like so:
{
"itemID":itemID,
"playerNames":[playerName1, playerName2, playerName3]
}
I need to be able to add to the list of playerNames quickly and efficiently.
Thank you!
If I understood your question correctly, you need to add items to the "playerNames" array. You can use one of the following operators:
If the player names array will have unique elements in it, use $addToSet
Otherwise, use $push

Dart observable list removed items

I just started to use observable list in dart. It notifies when the list is updated. When it's a removing case, it only gives me the index it removes from and how many items were removed. How am I supposed to know which items were removed since I only have indices and the 'updated' list (the items have already been removed from it.) I want to know if I miss something before I manually put extra code in it.
Thanks,
yi
The List removeAt() method returns the removed object. So, you can simply assign the value of removeAt() to a variable, like this:
var list = [obj0, obj1, obj2];
var first = list.removeAt(0);

How to use ContainerList in lwuit 1.5?

My list having variable length list items. ContainerList supports variable length list items. When I explored it on internet, I can't find any samples for ContainerList. Give me a sample piece of code to work on ContainerList.
LWUIT demo contains a ContainerList sample in the Scroll demo.
There is also an explanation in our blog http://codenameone.blogspot.com/
Generally ContainerList is a drop-in replacement for list, just replace the usage of List with ContainerList and it should work pretty seamlessly (albeit slower).
Try this:
Vector variableLengthVector = new Vector();
variableLengthVector.clear();
for(int i=0;i< variableLengthStringArray.length;i++)
{
variableLengthVector.add(variableLengthStringArray[i]);
}
List myListToBeDisplaye = new List(variableLengthVector);
variableLengthStringArray--> It contains the items that you wish to show in your list.
So whenever you want to display a list , just populate a vector and initialize your list with that vector. Ensure, that you clear that vector or re initialize the vector before populating it.
Now, simply paste your list on a form or wherever you wish to display it..
Ok, you can find stuff about containerList here:
http://lwuit.java.net/nonav/javadocs/com/sun/lwuit/list/ContainerList.html
You can use a container list like this:
ContainerList abc = new ContainerList(new DefaultListModel(variableLengthVector));

Flex4.6 Add element to top of List

I've got a spark list that gets dynamically filled.
So far the new items appear at the bottom of the list. What I'd like to do is to add them at the top.
The items in the list have a unique ID so some kind of sorting mechanism would probably do the trick as the new items have a greater ID than the old ones.
What I'd like to avoid is some complex method behind this as I'm working on a mobile platform and the list can get quite big so I need this to be as efficient as possible.
The list's data provider is an ArrayList that gets updated using binding.
How can that be done?
Thanks in advance!
u can Add the items at the starting index of the datagrid. Flex datagrid automatically renew all the indexes and add 1 to all existing element indexes. So
YourDataGridId.dataprovider.addItemAt(item,0) will do.