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.
Please give us feedback no matter whether you get your answer.
Please "Mark as Answer" if it's useful for you.
-_-
Member
375 Points
1033 Posts
int array
Jan 27, 2010 03:47 AM|LINK
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
amanbhullar
Contributor
2810 Points
480 Posts
Re: int array
Jan 27, 2010 04:51 AM|LINK
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
Aman Bhullar
ARLiveSupport.com
Mark as Answer, on the posts replys that helped you !!!.
HerryAtHotma...
Participant
1481 Points
259 Posts
Re: int array
Jan 27, 2010 04:54 AM|LINK
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
Das.Sandeep
Star
10652 Points
1897 Posts
Re: int array
Jan 27, 2010 04:55 AM|LINK
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 give us feedback no matter whether you get your answer.
Please "Mark as Answer" if it's useful for you.
Regards,
Sandeep
-_-
Member
375 Points
1033 Posts
Re: int array
Jan 27, 2010 05:31 AM|LINK
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.
sandy060583
Star
8714 Points
1624 Posts
Re: int array
Jan 27, 2010 06:21 AM|LINK
can u drop some code
?
Ramani Sandeep (My Blog)
(MCTS, MCC-2011)
Das.Sandeep
Star
10652 Points
1897 Posts
Re: int array
Jan 27, 2010 01:33 PM|LINK
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);
Please post your code or check with your datatable. Hope I will be able to solve your problem.
Please give us feedback no matter whether you get your answer.
Please "Mark as Answer" if it's useful for you.
Regards,
Sandeep