arrays

C# Serialization XML

Hello Everybody, just a simple question. Is there an attribute to skip empty arrays in the xml-serialization of c#? This would increase human-readability of the xml-output. Thanks in advance Matze ...

What exactly happens while you assign a reference to an element in Array in Java?

I am doing the following statements in Java, Obj t[] = new Obj[10]; Obj a = new Obj("a"); t[0] = a; a = new Obj("b"); t[1] = a; Why in java, when i access t[0] , it returns me "a", rather than "b"? Is this because of the GC? and can i believe it is safe to do such an operation ...

Shortest method to convert an array to a string in c#/LINQ

Closed as exact duplicate of this question. I have an array/list of elements. I want to convert it to a string, separated by a custom delimitator. For example: [1,2,3,4,5] => "1,2,3,4,5" What's the shortest/esiest way to do this in c#? I have always done this by cycling the list and checking if the current element is not the last on...

In C arrays why is this true? a[5] == 5[a]

As Joel points out in Stack Overflow podcast #34, in C Programming Language (aka: K & R), there is mention of this property of arrays in C: a[5] == 5[a] Joel says that it's because of pointer arithmetic but I still don't understand. Why does a[5] == 5[a] ? Edit: The accepted answer is great. For a lower level view of how this works, se...

Using arrays or std::vectors in C++, what's the performance gap?

In our C++ course they suggest not to use C++ arrays on new projects anymore. As far as I know Stroustroup himself suggests not to use arrays. But are there significant performance differences? ...

(PHP) Object of class SoapClient could not be converted to string

This code works fine: $result = $client->__call("optionalInfo", array( new SoapParam("...", "client"), new SoapParam("...", "add_code")) ); When I try abstracting it a bit to make the script re-usable, I get this error: Catchable fatal error: Object of class SoapClient could not be converted to string The broken code is: ...

Why do compilers not warn about out-of-bounds static array indices?

A colleague of mine recently got bitten badly by writing out of bounds to a static array on the stack (he added an element to it without increasing the array size). Shouldn't the compiler catch this kind of error? The following code compiles cleanly with gcc, even with the -Wall -Wextra options, and yet it is clearly erroneous: int ma...

PHP - Iterating multiple $_post arrays

Hi all, I have the following code: <tr> <td width="60%"><dl> <dt>Full Name</dt> <dd> <input name="fullname[]" type="text" class="txt w90" id="fullname[]" value="<?php echo $value; ?>" /> </dd> </dl></td> <td width="30%"><dl> <dt>Job Title</dt> <dd>...

IndexOutOfRangeException for an IList<T>

I am implementing a list, and I am wondering about the definition of the IndexOutOfRange. Which one of the following do you think is better? /// <exception cref="IndexOutOfRangeException">if index is less than 0 /// or greater than <see cref="Count"/> public T this[int index] { get { return myArray[index]; } } Or /// <exception cref=...

What is the easiest alternative to a generic array in Java?

Suppose I have this: class test<T> { private T[] elements; private int size; public test(int size) { this.size = size; elements = new T[this.size]; } } It seems this isn't possible because the compiler doesn't know what constructor to call once it tries to replace the generics code or something. Wha...

Checking 2-dimensional array (like eight queens puzzle)

My problem is very similar to eight queens puzzle. I've got 2-dimensional array (N x N) that for example, looks like this: 0,0,0,0,1 y 0,0,0,0,0 | 0,0,0,0,0 V 0,0,0,1,0 0,0,0,0,0 x-> I'm checking horizontally, vertically and diagonally for occurrences of 1 \,0,|,0,/ 0,\,|,/,0 -,-,1,-,- 0,/,|,\,0 /,0,|,0,\ I'm thinking about storin...

javascript cannot call an element in array

Ok, let me explain more... the goal is to make the checkbox checked if there's a change on select. The actual code was: function checkit(date) { document.forms[0].date.checked = true; } <input type="checkbox" name="date[]" value="2008-08-14">Aug 14, 2008<br> <select name="slot[]" size="1" onchange="checkit(date[]);"/> <option val...

Converting an array of Pixels to an image in C#

I have an array of int pixels in my C# program and I want to convert it into an image. The problem is I am converting Java source code for a program into equivalent C# code. In java the line reads which displays the array of int pixels into image: Image output = createImage(new MemoryImageSource(width, height, orig, 0, width)); can so...

how to decompose integer array to a byte array (pixel codings)

Hi sorry for being annoying by rephrasing my question but I am just on the point of discovering my answer. I have an array of int composed of RGB values, I need to decompose that int array into a byte array, but it should be in BGR order. The array of int composed of RGB values is being created like so: pix[index++] = (255 << 24) | (r...

Arrays, what's the point?

As I'm programming I haven't seen an instance where an array is better for storing information than another form thereof. I had indeed figured the added "features" in programming languages had improved upon this and by that replaced them. I see now that they aren't replaced but rather given new life, so to speak. So, basically, what's ...

Pixel Programming continued

I have got a byte array of pixels in BGR order and I want to create an image out of it in C#. Can anyone offer code or advice? ...

Defend zero-based arrays

A question asked here recently reminded me of a debate I had not long ago with a fellow programmer. Basically he argued that zero-based arrays should be replaced by one-based arrays since arrays being zero based is an implementation detail that originates from the way arrays and pointers and computer hardware work, but these sort of stuf...

Best way to transfer an array between PHP and Javascript

So I have an array of records retreived from a database. The array is in the format; $rows[0]['id']=1; $rows[0]['title']='Abc'; $rows[0]['time_left']=200; $rows[1]['id']=2; $rows[1]['title']='XYZ'; $rows[1]['time_left']=300; //And so on upto 10-20 rows What's the best/most elegant way of transferring this array over to my javascript...

When to use a linked list over an array/array list?

I use a lot of lists and arrays but I have yet to come across a scenario in which the array list couldn't be used just as easily as, if not easier than, the linked list. I was hoping someone could give me some examples of when the linked list is notably better. ...

Algorithm for 'Syncing' 2 Arrays

Array 1 | Array 2 ================= 1 | 2 2 | 3 3 | 4 5 | 5 | 6 What is a good algorithm to 'sync' or combine Array 2 into Array 1? The following needs to happen: Integers in Array 2 but not in Array 1 should be added to Array 1. Integers in both Arrays can be left alone. Integers in Array 1 ...