# How to get Max value [Answered]RSS

## 2 replies

Last post Oct 21, 2014 05:56 AM by raju dasa

Member

64 Points

127 Posts

### How to get Max value

Oct 21, 2014 05:29 AM|Shibly|LINK

how to get maximum value for every row in a 2D array. Can any one help me please.

Thanks in advance.

csharp .net

All-Star

50500 Points

14821 Posts

### Re: How to get Max value

Oct 21, 2014 05:44 AM|oned_gk|LINK

Try this

```        int[] max = new int[array.GetUpperBound(0)];
for (int x = 0; x <= array.GetUpperBound(0); x++)
{
for (int y = 0; y <= array.GetUpperBound(1); y++)
{
if(max[x] < array[x, y])
{
max[x] = array[x, y];
}
}
}```

csharp .net

Programming to simplify, don't look for hardway ...
Suwandi - Non Graduate Programmer

All-Star

15146 Points

3884 Posts

### Re: How to get Max value

Oct 21, 2014 05:56 AM|raju dasa|LINK

Hi,

Try this code:

```        var arr = new int[2,3]{{1,2,3},{4,5,6}};
List<int> max= new List<int>();
for (int x = 0; x < arr.GetLength(0); x++)
{
int item = 0;
for (int y = 0; y < arr.GetLength(1); y++)
{
if(item < arr[x, y])
{
item = arr[x, y];
}
}
max.Add(item);
}```

csharp .net

Happy Coding ! Mark as Answer if it helps.
rajudasa.blogspot.com  ||  rajudasa-tech