473,794 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(temp o);
Array.Sort(sear ch);

for (int bcl = 0; bcl < tempo.GetLength (0); bcl++)
{
System.Console. Write("Cherche {0}", search[bcl]);
if (Array.BinarySe arch(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("temp o[{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 7122
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.Cont ainsKey(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
2875
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 returns a reference to the found item.
7
8776
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 COUNTRY_CODE, COUNTRY_$lang FROM countries WHERE CONTINENT_CODE = $i ORDER BY COUNTRY_$lang ASC"); $j = 0; while ($row = mysql_fetch_array($search_countries, MYSQL_NUM)) { $countries = $row;
5
2939
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]; Array.prototype.findValue = function(val) { // blah }
11
39471
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 rst.EOF i = i + 1 If rst!Something = Then astrMyArray(i) = rst!Something
11
24149
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 memchr(), memcmp(), memmove() a lot. Is there an ANSI C maximium size for character arrays which are guaranteed to succeed, assuming the machine has sufficient memory? And will the memxxx() functions work with that size? I'm looking at hopefully...
7
7417
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 example, the manner in which I update element 1 depends on several other (randomly numbered) elements in the array. So, I can't change an element until I've figured out how every element changes.
23
7421
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 in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
7
12725
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 type="text/javascript"> var aInvestor = {1448:"4Imprint Group plc Pension Scheme", 1061:"Aargau Pensionskasse",659:"ABB Koncernens Pensionsstiftelse",
7
11790
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) Your first task is to write a program which reads this file into two parallel arrays in memory. One array contains the titles, and the other array contains the authors. The arrays are 'parallel' in the sense that the n-th element of the authors...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6779
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.