Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New at C#

Status
Not open for further replies.

Hobeau

MIS
Apr 19, 2004
77
0
0
US
Hi, I'm a newbie at C#. I know how to do this in VB, but I'm trying to write a function in C# that will take 2 arrays (array1[8], array2[8]) and find the mode (most frequent number) out of both of them. I was thinking that maybe I could build the 2 arrays into one new temporary array or something like that. I was thinking also that I'll be needing a couple "for" loops. Can anyone help? Thanx.
 
post the VB script and we'll try to translate it for you to C# code

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Why do you need to combine the 2 loops into one?

Do you know the range of numbers that can be in your arrays?

you just need 3 loops

so the process would be;

declare a temporary 2 dimensional array for storage
1 dimension needs to be as many elements long as your 2 arrays have in total. The other is 2 elements long.

Loop through array 1
look at an element.
Look in the temporary array tosee if this number has been recorded yet
If no, add it to the temporary array, and score 1 in the second column
If Yes, add 1 to the number in the second column (the total number of instances of this number in the array)

Repeat this to loop through array 2

Loop thru the temporary array, to find out which number has the highest score inthe second column. i.e. which is the modal number.

this is all basic stuff to do in c#, or vb.net, so if you can write this code in one, you can write in the other. (in fact, iirc, MSDN has examples for most of the functions in C# and VB.net, so look at your vb code, adn go to help when u get stuck !)

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top