Sort thru arrays for elements
C#
3
Posts
3
Posters
0
Views
1
Watching
-
I have an array with 4 elements in each record of 8 records, the first element is a string, the other 3 are int. How do I pull the 3 elements, i.e., 98, 97, 98 from the record, then add them together? Thanks
-
I have an array with 4 elements in each record of 8 records, the first element is a string, the other 3 are int. How do I pull the 3 elements, i.e., 98, 97, 98 from the record, then add them together? Thanks
create a class
public class array_of_4element() { public array_of_4element(string s, params int[] i) { str = s; num.CopyTo(i,0); } string str; int[] num = new int[3]; public int sum() { return num[0]+num[1]+num[2]; } }
so your
onetreeup wrote:
an array with 4 elements in each record of 8 records
would be done in
List<array_of_4element> 8_records = new List<array_of_4element>(8); // add first record array_of_4element arr = new array_of_4element("text1", 98,97,98); 8_records.Add(arr); // get first record, sum of num values 8_records[0].sum();
8.Kelvin()
{
while (!(the machine can program itself))
Wont_stop_coding = true;
}modified on Monday, March 23, 2009 12:24 AM