473,396 Members | 2,024 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,396 software developers and data experts.

dynamic length arrays

This article:
http://www.c-sharpcorner.com/UploadF...ithArrays.aspx
claims that "In C#, arrays can be declared as fixed length or
dynamic".

I don't believe he is correct. With the exception of collections /
arraylists, can you have a dynamically sized array in C#? Note that i
am aware of Array.Resize<type>(ref myArray, newsize); for resizing
arrays in .NET 2.0. Is there a way to resize the array dynamically,
as Mahesh Chand claims (but doesn't show) in his article?

It mentions the System.Array class, which does hav a IsFixedSize
property, so maybe I can use that to make an array that is dynamic in
size.

(I think Mahesh Chand's article was written quickly, because he claims
the binary search will work without requirement of sorting. I've seen
this in other tutorials for VB, as well. It's like these things are
just written in 5 minutes and posted. And I have to register and log
in to write a comment to help him correct it.)

Zytan

Feb 25 '07 #1
10 3682
Oh, and I already know about ArrayList. But, this article is talking
about arrays, not collections, which is what ArrayList is.

thanks,

Zytan
Feb 25 '07 #2
Correct:
http://msdn2.microsoft.com/en-us/lib...fixedsize.aspx

"Array implements the IsFixedSize property because it is required by the
System.Collections.IList interface."
Feb 25 '07 #3
Correct:http://msdn2.microsoft.com/en-us/lib...fixedsize.aspx
>
"Array implements the IsFixedSize property because it is required by the
System.Collections.IList interface."
Ok, just to be clear, arrays are fixed in size? The IsFixedSize
property is only because it is required for the above?

Zytan

Feb 25 '07 #4
Zytan wrote:
>Correct:http://msdn2.microsoft.com/en-us/lib...fixedsize.aspx

"Array implements the IsFixedSize property because it is required by the
System.Collections.IList interface."

Ok, just to be clear, arrays are fixed in size? The IsFixedSize
property is only because it is required for the above?

Zytan
Yes.

It's actually impossible to resize an array in .NET. The methods that
are used for resizing an array are actually creating a new array and
copies the data to it.

--
Göran Andersson
_____
http://www.guffa.com
Feb 25 '07 #5
It's actually impossible to resize an array in .NET. The methods that
are used for resizing an array are actually creating a new array and
copies the data to it.
thanks, Göran. I knew this, but thanks for being clear.

Zytan

Feb 25 '07 #6

"Göran Andersson" <gu***@guffa.comwrote in message
news:es*************@TK2MSFTNGP05.phx.gbl...
Zytan wrote:
>>Correct:http://msdn2.microsoft.com/en-us/lib...fixedsize.aspx

"Array implements the IsFixedSize property because it is required by the
System.Collections.IList interface."

Ok, just to be clear, arrays are fixed in size? The IsFixedSize
property is only because it is required for the above?

Zytan

Yes.

It's actually impossible to resize an array in .NET. The methods that are
used for resizing an array are actually creating a new array and copies
the data to it.
A .NET array is dynamic because the memory is dynamically allocated (from
the gc heap, or even from the stack), and the size is therefore determined
at runtime. That's all dynamic length means, not the ability to resize in
place.

OTOH, C# also supports fixed buffers, where the data is inline in the larger
type. Since the size is fixed at compile time, it fails the "dynamic" test.

http://blogs.msdn.com/ericgu/archive...12/213676.aspx
>
--
Göran Andersson
_____
http://www.guffa.com

Feb 27 '07 #7
A .NET array is dynamic because the memory is dynamically allocated (from
the gc heap, or even from the stack), and the size is therefore determined
at runtime. That's all dynamic length means, not the ability to resize in
place.
Thanks for clearing it up.
OTOH, C# also supports fixed buffers, where the data is inline in the larger
type. Since the size is fixed at compile time, it fails the "dynamic" test.

http://blogs.msdn.com/ericgu/archive...12/213676.aspx
Wow, thanks, that's cool.

Zytan

Feb 27 '07 #8
OTOH, C# also supports fixed buffers, where the data is inline in the larger
type. Since the size is fixed at compile time, it fails the "dynamic" test.

http://blogs.msdn.com/ericgu/archive...12/213676.aspx
C# is clear that the following is true:

"Pointers and fixed size buffers may only be used in an unsafe
context."
"Unsafe code may only appear if compiling with /unsafe."

So, it looks like its best to stay away from fixed size buffers.
But, thanks for letting us know about them.

Zytan

Feb 27 '07 #9
Ben Voigt wrote:
A .NET array is dynamic because the memory is dynamically allocated (from
the gc heap, or even from the stack), and the size is therefore determined
at runtime. That's all dynamic length means, not the ability to resize in
place.
No, .NET arrays are not dynamic. They are dynamically allocated, but
that doesn't make them dynamic. A dynamic array is resizable.

http://en.wikipedia.org/wiki/Dynamic_array

--
Göran Andersson
_____
http://www.guffa.com
Feb 27 '07 #10
No, .NET arrays are not dynamic. They are dynamically allocated, but
that doesn't make them dynamic. A dynamic array is resizable.

http://en.wikipedia.org/wiki/Dynamic_array
Göran, you are completely right. This distinction is important. I
wish I could change my earlier posts.

Thank you.

Zytan

Feb 27 '07 #11

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

Similar topics

4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course doesnt cover the issue. Its probably something...
4
by: Robert | last post by:
Hi, How can i resize an array of strings to add more? This is an example i just downloaded from a website: char *cpArray; int i; for (i = 0; i < 10; i++) cpArray = (char *)malloc(20 *...
5
by: swarsa | last post by:
Hi All, I realize this is not a Palm OS development forum, however, even though my question is about a Palm C program I'm writing, I believe the topics are relevant here. This is because I...
6
by: Fernando Barsoba | last post by:
Hi all, I have a simple question regarding dynamic memory allocation.. is there a way to create a variable for which we don't know its size using the 'stack' instead of the 'heap'? For instance,...
3
by: genc ymeri | last post by:
Hi, What can I use in C# for dynamic arrays ???? I have some records (struts in ..Net) and want to store them in a dynamic "arrays" or object list. I noticed the in C# arrays' length can't be...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
4
by: learnfpga | last post by:
Here is a little code I wrote to add the numbers input by the user.....I was wondering if its possible to have the same functionality without using dynamic arrays.....just curious..... ...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.