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<ty pe>(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 10 3717
Oh, and I already know about ArrayList. But, this article is talking
about arrays, not collections, which is what ArrayList is.
thanks,
Zytan
Correct: http://msdn2.microsoft.com/en-us/lib...fixedsize.aspx
>
"Array implements the IsFixedSize property because it is required by the
System.Collecti ons.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
Zytan wrote:
>Correct:http://msdn2.microsoft.com/en-us/lib...fixedsize.aspx
"Array implements the IsFixedSize property because it is required by the System.Collect ions.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
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
"Göran Andersson" <gu***@guffa.co mwrote in message
news:es******** *****@TK2MSFTNG P05.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.Collec tions.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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 simple, but its just not popping into my mind
at the moment.
My little snippet of code is below. Basically, the studentID array is
dynamic so it will fit any length of a Student's Name. What I'm trying to
do is place this chunk of code into a...
|
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 * sizeof(char));
strcpy(cpArray, "A hat is on the mat");
|
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 believe the problem centers
around my handling of strings, arrays, pointers and dynamic memory
allocation. Here is the problem I'm trying to solve:
I want to fill a list box with a list of Project Names from a database
(in Palm this is more...
|
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, I have the following:
> #define MESG_LENGTH 12
> unsigned char packet;
|
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 extented in run time. So, what
should I use ?
Thank You in advance.
PS:
| |
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) {
.....
}
|
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.....
//trying to get input from the user to add all the numbers that user
inputs
//tried to do it without dynamic memory usage but probably cannot
achieve it
//here is using "new" and "delete" operator....
|
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 in an
array. The application compiles but aborts without giving me any useful
information.
What I suspect is happening is infinite recursion. Each Directory
object creates an array of Subdirectories each of which has an array of...
|
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
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |