473,237 Members | 1,260 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,237 software developers and data experts.

Array search

Hello,

I'm a very very newbie in C# I did start 2 days ago, I get Visual
Stuido 2005 C#

I try to understand how to manage the arrays
I did write this

int[] tempo=new int[3];
int[,] list = { { 1, 2, 3 } , { 11,12,13} };
int[] search = { 15, 123, 12 };

I have to goals here

My main goal is to find if values in array search exist in list[0]
and list[1]

My only idea, with my knowledge, is

- 1st to copy all the value of the multi-dimensional array list[1,] to
a tempo array

- to search in the temporary array, all the value of search, I
programmed the method contains for that.

To be frank I'm sure there is much simpler than this.

Thank you fro your help

namespace loto_Sharp
{

class Program
{
// Search value of array search in the temporary array tempo
private static bool contains(int[] tempo,int[] search)
{
Array.Sort(tempo);
Array.Sort(search);

for (int bcl = 0; bcl < tempo.GetLength(0); bcl++)
{
System.Console.Write("Cherche {0}", search[bcl]);
if (Array.BinarySearch(tempo, search[bcl]) >= 0)
{
System.Console.WriteLine(" - {0} Found",
search[bcl]);
return true;
}
else
{
System.Console.WriteLine(" - {0} Not found",
search[bcl]);
}
}
return false;
}
static void Main(string[] args)
{
int[] tempo=new int[3];
int[,] list = { { 1, 2, 3 } , { 11,12,13} };
int[] search = { 15, 123, 12 };

for (int bcl1 = 0; bcl1 < list.GetLength(0); bcl1++) //
from 0 to 1 there is 2 array in list
{
for (int bcl = 0; bcl < list.GetLength(1); bcl++) //
from 0 to 2 there is 3 elements in each array of list
{
tempo[bcl] = list[bcl1, bcl]; // I do convert a
multi array into a single array
System.Console.WriteLine("tempo[{0}]={1}", bcl,
tempo[bcl]);
}

if (contains(tempo, search))
System.Console.WriteLine("= FOUND ="); else
System.Console.WriteLine("= not FOUND ="); ;
System.Console.WriteLine("======================== ========================");
}
}

}
}
Jan 24 '06 #1
1 7079
cyrvb wrote:
Hello,

I'm a very very newbie in C# I did start 2 days ago, I get Visual
Stuido 2005 C#

I try to understand how to manage the arrays
I did write this

int[] tempo=new int[3];
int[,] list = { { 1, 2, 3 } , { 11,12,13} };
int[] search = { 15, 123, 12 };

I have to goals here

My main goal is to find if values in array search exist in list[0]
and list[1]

My only idea, with my knowledge, is

- 1st to copy all the value of the multi-dimensional array list[1,] to
a tempo array

- to search in the temporary array, all the value of search, I
programmed the method contains for that.

To be frank I'm sure there is much simpler than this.


you can save yourself the binary search by using a Dictionary<int,
object> and store all ints in list 0 and list 1 in the key (and null in
the value) then do a dictionary.ContainsKey(value) for each value in
your array.

FB
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jan 24 '06 #2

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

Similar topics

5
by: Nico | last post by:
Hello folks, I am currently storing a set of objects inside an array, $itemlist = array(); $itemlist = new item("myitem"); //... and I am looking to develop a search function, which...
7
by: bettina | last post by:
I want to define an array bidimensional as a session array. <? $continents = array (1 => $europe, $america, $oceania, $africa, $asia); $i = 1; do { $search_countries = mysql_query("SELECT...
5
by: Andrew Poulos | last post by:
If I'm searching for an occurance of a value in a multi-dimensional array how can I get it's index returned as an array, if found? For example, if: foo = new Array(); foo = , 5, , 9, 10]; ...
11
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not...
11
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I've noticed a few threads (full of sound and fury, signifying nothing) here recently about allocation of large memory blocks. I'm about to start on a personal pet project where I'll be using...
7
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
7
by: mark4asp | last post by:
How can I use name:value pairs like an array? 1. I want to load data on to the page which will be used to populate a list box (see example below): <html> <head> <script...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.