Click here to Skip to main content
15,882,315 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to Find max value from the first column of 2 D array and then convert this row to 1d array and finally delete row from 2d array and I need to repeat this process many times so I have to delete row each time I found the max for example this is my 2d array { {3,5,7},{4,9,8},5,9,1}} so I suppose to make as 1d array and 2d array will be {{3,5,7},{5,9,1}} any help please
Posted
Updated 22-Dec-15 20:19pm
v2

1 solution

In .NET, you cannot change the size of an array, its rank and so on — you can only modify any element of the array.

If you want to add/remove anything, use collections instead, for example, the simplest one, System.Collections.Generic.List<>. Note that the instance of List can be converted to array when you populate it.

Don't be confused with the method System.Array.Resize — despite this name (yet another confusing Microsoft name!), it does not resize anything; instead, it creates a brand new array, which is too expensive to take seriously, better use collection, in nearly all cases. The fact that the new array instance is created is mentioned in the "Remark" section of the MSDN help page, Array.Resize(T) Method (T[], Int32) (System)[^].

Arrays are only good when you know the rank and the length in each dimension in advance, when you create an instance of an array.

—SA
 
Share this answer
 
Comments
Member 12101107 23-Dec-15 4:11am    
Well, do you mean list of lists,to be honest I'm never work with it's so can I deal with it like 2D array
Sergey Alexandrovich Kryukov 23-Dec-15 11:36am    
Do you think "never work" makes a lot of difference? Also, list is a list, what's the difference, list of what?
If everything only worked with what this person worked before, where some engineers would come from? :-)
All you need it stop it and, yes, work with lists of lists, lists of array, whatever is suitable.

Anyway, I have you a comprehensive answer. Even "you cannot" part along would be a comprehensive answer. Are you going to accept it formally?

—SA
Member 12101107 23-Dec-15 13:31pm    
As you said ,I spend all the day working with list (of list)changing all my code to be suitable to it,but at point of find max I Could find it and convert it's row to array ,but still have problem with deleting this row
Sergey Alexandrovich Kryukov 23-Dec-15 14:54pm    
...and did not explain what's the problem. I already explained you that you cannot remove anything from an array. Use my advice to work only with lists (or other collections, depending on what you need). If you have a list of rows, you can delete a row, no matter if it's an array or anything else.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900