473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Clear Array

ron
Hi,
Could i clear the a single dimension array and a jagged
array in the following way.

int[] mySingleArr = new int[10];

mySingleArr = System.Array.Clear();

int[][] myJaggedArr = new int[3][];
myJaggedArr = new int[0][3];
myJaggedArr = new int[1][3];
myJaggedArr = new int[2][3];

myJaggedArr = System.Array.Clear();

Is this possiable without iterating through the arrays
and setting the elements to zero?

Thanks Ron

Nov 15 '05 #1
2 14583
I don't know what exactly you're getting at, but why don't you just use
multi-dimensional arrays like this:

int[,] a2Darray = new int[4, 10];
a2Darray[0,0] = 1;
a2Darray[0,1] = 2;
....[etc]...

What you're doing with your "jagged" array is creating an array inside of an
array.. that's old C style. C# has new built-in features for
multi-dimensional arrays.

Chris LaJoie
"ron" <goodr@no_spam_for_me_mddm.panasonic.com> wrote in message
news:03****************************@phx.gbl...
Hi,
Could i clear the a single dimension array and a jagged
array in the following way.

int[] mySingleArr = new int[10];

mySingleArr = System.Array.Clear();

int[][] myJaggedArr = new int[3][];
myJaggedArr = new int[0][3];
myJaggedArr = new int[1][3];
myJaggedArr = new int[2][3];

myJaggedArr = System.Array.Clear();

Is this possiable without iterating through the arrays
and setting the elements to zero?

Thanks Ron

Nov 15 '05 #2
ron <goodr@no_spam_for_me_mddm.panasonic.com> wrote:
Could i clear the a single dimension array and a jagged
array in the following way.

int[] mySingleArr = new int[10];

mySingleArr = System.Array.Clear();
No, because Array.Clear takes arguments and returns void. You mean:

Array.Clear (mySingleArr, 0, mySingleArr.Length);
int[][] myJaggedArr = new int[3][];
myJaggedArr = new int[0][3];
myJaggedArr = new int[1][3];
myJaggedArr = new int[2][3];

myJaggedArr = System.Array.Clear();

Is this possiable without iterating through the arrays
and setting the elements to zero?


In this case you're not actually wanting to clear myJaggedArr itself,
which would set it back to being an array of 3 null references, but
each member of those three arrays - so you need to do precisely that:

foreach (int[] subArray in myJaggedArr)
{
Array.Clear (subArray, 0, subArray.Length);
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: seia0106 | last post by:
Hello, Writing a program in c++ that should use complex numbers I have two choices before me. 1- define a struct for complex data i.e struct {float real,imag; }ComplexNum; 2-use an array...
5
by: deko | last post by:
I use a For Each... Next loop like this: For Each varFnm In Array("This", "That", "OtherThing", "Foo", "Bar") RunSql ("UPDATE.... bla bla bla) Next But the exact same elements of the Array...
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
21
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each...
13
by: DazedAndConfused | last post by:
Is there a quick way to fill an array with zeros or make all elements empty/nothing?
4
by: Armand | last post by:
Hi Guys, I have a set of array that I would like to clear and empty out. Since I am using "Array" not "ArrayList", I have been struggling in finding the solution which is a simple prob for those...
5
by: trint | last post by:
Hi, I have several arrays that look like this: string productsString0 = new string; After they are no longer needed, How can I reset them as though the program were just started? Thanks,...
35
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the...
2
by: ganesh22 | last post by:
Hi, In my below code i want to clear array btn_arr How? if (btn_arr is TextBox) { //for each button saved in our array, recreate it foreach...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.