I have two or more arrays -- one with IDs, one or more with string values. I want to merge these into a hash table so I can look up values by ID.
The following function does the job, but a shorter and sweeter version (LINQ?) would be nice:
Dictionary<int, string[]> MergeArrays( IEnumerable<int> idCollection,
...
Given the type:
class Field{
public string Name{get;set;}
public string[] DependsOn{get;set;}
}
Let's say I have an array of Field items:
List<Field> fields = new List<Field>();
fields.Add(new Field() { Name = "FirstName" });
fields.Add(new Field() { Name = "FullName",
DependsOn = new[] {"FirstName",...
Most of my programming experience is in a language where there is one collection data structure -- an array. Now that I'm working primarily in .NET, I've come to appreciate the vast number of tools available to me, but I also find it difficult to determine which tools is best suited for each problem. I find this to be the case often wi...
How can I add a new key/value pair to an existing array inside of nested foreach loops and have that pair persist outside the scope of the loops?
<?PHP
include('magpierss/rss_fetch.inc');
/*
one, two, skip a few...
$urls is an associative array with
database indices as keys and
URLs as values
...
I've got a file INPUT that has the following contents:
123\n
456\n
789
I want to run my script like so: script.rb < INPUT and have it convert the contents of the INPUT file to an array, splitting on the new line character. So, I'd having something like myArray = [123,456,789]. Here's what I've tried to do and am not having much luck:
...
I'm attempting to make a data structure to represent a Maze in C++.
All the data I need to hold about the maze can be stored in 16 bit integers using bitwise operations (to represent each cell of the maze):
16 bit unsigned integer
So, I figured a 2d array of 16bit integers and I'm good to go for my Maze data structure. I wanted to ke...
Hi, I'm trying to create an array of arrays that will be using repeated data, something like below:
int[] list1 = new int[4] { 1, 2, 3, 4};
int[] list2 = new int[4] { 5, 6, 7, 8};
int[] list3 = new int[4] { 1, 3, 2, 1 };
int[] list4 = new int[4] { 5, 4, 3, 2 };
int[,] lists = new int[4, 4] { list1 , list2 , list3 , list4 };
I ca...
I've got a multidimensional array:
foo = [["a","b","c"], ["d", "e", "f"], ["g", "h", "i"]]
Now I need to ruturn the "coordinates" of "f", which should be (1,2). How can I do this without knowing which "row" "f" is in? I've been trying to use the index method, but this only works when I tell it where to look, i.e.
foo[1].index("f") #...
I have tried this example of array of pointers. I am getting the error "Illegal initialisation in function main"
int main()
{
int a[]={1,2,3,4,5};
int b[]={1,2,3,4,5};
int c[]={1,2,3,4,5};
int *p[3]={a,b,c};
int i;
clrscr();
for(i=0;i<3;i++)
printf("%d - %u\n",*p[i],p[i]);
getch();
}
If I use stati...
(can you tell I'm learning Ruby today? :))
I want to determine if the multidimensional array I'm working with is a 'rectangle'--i.e., the rows are the same size. Here's what I'm doing, which works but feels clunky.
if @myArray[0].size != @myArray[[email protected]].size
raise "This array is not a rectangle."
end
Basically, I'm check...
Judy array is fast data structure that may represent a sparse array or a set of values. Is there its implementation for managed languages such as C#? Thanks
...
Ok so I have the following code. I'm trying to output some xml so that it can be read with jQuery, but for whatever reason, when I try to add an element in the array to a variable, it just turns the variable to 0. I did a print_r() on the array, and it's normal.
Code
if ($content == "tables") {
$result = mysql_query("show tables");...
In the question "Is returning a whole array from a Perl subroutine inefficient" two people recommend against optimizing if there is no need for it. As a general rule, optimizing can add complexity, and if it's not needed, simple is better. But in this specific case, returning an array versus an array ref, I don't see that there's any a...
Hi
In PHP, will these always return the same values?
//example 1
$array = array();
if ($array) {
echo 'the array has items';
}
// example 2
$array = array();
if (count($array)) {
echo 'the array has items';
}
Thank you!
...
I need to have a static void* array[1024]; in a library and i need to have it set to NULL for every entries.
My question is about the best way to set the entire array to NULL, is a memset (array, NULL, sizeof (void*) * 1024) the best solution?
...
If I have a loop that requests my data from my form:
for ($i=0;$i < count($_POST['checkbx']);$i++)
{
// calculate the file from the checkbx
$filename = $_POST['checkbx'][$i];
$clearfilename = substr($filename, strrpos ($filename, "/") + 1);
echo "'".$filename."',";
}
how do I add that into the sample ...
I know that it's more performant to use '' delimited strings rather than ""...
but I was wondering if there's any performance improvemente doing this
$a = array( 'table' => 'myTable', 'order' => 'myOrder' );
$table = $a['table']
instead of
$a = array( table => 'myTable', order => 'myOrder' );
$table = $a[table]
I guess so, bu...
how do you initialize and uninitialize a multidimensional character array in C++?
...
Lets assume I have an array in PHP:
$array = array("apple", "banana", "cap", "dog", etc..) up to 80 values.
and a string variable:
$str = "abc";
If I want to check whether this string ($str) is exists in the array or not, I use preg_match function. Which is like this:
$isExists = preg_match("/$str/", $array);
if ($isExists){
...
On a quad-core machine, I am considering the parallelization of C#/.NET algorithm which involves having multiple threads reading the small int[] array concurrently. So far, it seems to be working rather well, but I am not sure where it is specified that concurrent reads on an array are thread-safe in .NET. Any pointers?
Then, I am also ...