6 replies

Last post Jan 27, 2010 01:33 PM by Das.Sandeep

Member

375 Points

1033 Posts

int array

how can i convert the column data in datatable to integer array
the column data in datatable stored as:
1
2
3
4

after store to integer array,how can i get the max value in array

Contributor

2810 Points

480 Posts

Re: int array

For clumn data to array, chak the post
http://www.davesquared.net/2007/04/converting-values-for-datacolumn-to.html

For Max in array check
http://www.dreamincode.net/code/snippet2322.htm

Regards
Aman Bhullar
ARLiveSupport.com

Participant

1481 Points

259 Posts

Re: int array

hi.

you can get  MAX number in column without converting  datatable column to  int Array using following code.

string MaxNo = dt.Select("seq_no=max(seq_no)")[0][0].ToString();

here seq_no is name of column in datatable(dt).

Thanks.

datatable

Haresh Dhameliya

Star

10652 Points

1897 Posts

Re: int array

Hello,

I have created one function in which you will get Max integer, I assume that there is no default function from array in which we can get directly Max value. Hope it will fulfill your requirement. Please let me know if you need more details.

static int MaxValue(int[] intArray)
{
int maxVal = intArray[0];
for (int i = 1; i < intArray.Length; i++)
{
if (intArray[i] > maxVal)
maxVal = intArray[i];
}
return maxVal;
}
protected void Page_Load(object sender, EventArgs e)
{

int[] myArray = {
1, 8, 3, 6, 2, 5, 9, 3, 0, 2
};
int maxVal = MaxValue(myArray);
Response.Write("The maximum value in myArray is {0} " + maxVal);
}

Please let me know if you need more help.

Regards,

Sandeep
• Edited by Das.Sandeep on Jan 27, 2010 04:57 AM
• Marked as answer by -_- on Jan 27, 2010 04:01 PM

Member

375 Points

1033 Posts

Re: int array

I can't get the number, it always shows the number 82??? even i change to get another column's max number , its also 82.

Star

8714 Points

1624 Posts

Re: int array

can u drop some code

?

Ramani Sandeep (My Blog)
(MCTS, MCC-2011)

Star

10652 Points

1897 Posts

Re: int array

-_-

I can't get the number, it always shows the number 82??? even i change to get another column's max number , its also 82.

I have tested more that 82 then it is working fine and display 91.

int[] myArray = {
1, 8, 3, 6, 2, 5, 9, 3, 0, 2,91,87,21,80,81
};
int maxVal = MaxValue(myArray);
Response.Write("The maximum value in myArray is {0} " + maxVal);