I would like to know how the following will be handled in the .net
framework:
Pl. don't pay attention to the syntax
int a[10]
int b
a[1]=2
a[2]=2
a[3]=2
a[5]=2
a[7]=2
a[8]=2
b=a.length % using the in-built function to find the array length
Rest of 'a' is not assigned any valu
I get the value of 'b' to be the length of first n values of 'a' which
have been initialized, i.e. the array is treated as complete once an
uninitialized array element is encountered.
Can someone give me an insight into why this is so?
Thank you. 3 1650
Madhu,
First, this probably doesn't belong in ASP.NET since its a C# language
question and has virtually nothing to do with ASP.NET.
Second, let's do it right:
int[] a= new int[10];
int b=0;
a[1]=2;
a[2]=2;
a[3]=2;
a[5]=2;
a[7]=2;
a[8]=2;
b=a.Length;
Console.WriteLi ne(b);
Console.ReadLin e();
In the example, b will ALWAYS be 10 because that is the Length of the Array
you've declared, whether you filled any, some or even none of the elements -
they all are initialized to their default type values.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Madhu" wrote: I would like to know how the following will be handled in the .net framework: Pl. don't pay attention to the syntax
int a[10] int b
a[1]=2 a[2]=2 a[3]=2 a[5]=2 a[7]=2 a[8]=2
b=a.length % using the in-built function to find the array length
Rest of 'a' is not assigned any valu I get the value of 'b' to be the length of first n values of 'a' which have been initialized, i.e. the array is treated as complete once an uninitialized array element is encountered.
Can someone give me an insight into why this is so?
Thank you.
Peter wrote: Madhu, First, this probably doesn't belong in ASP.NET since its a C# language question and has virtually nothing to do with ASP.NET.
Second, let's do it right:
int[] a= new int[10]; int b=0; a[1]=2; a[2]=2; a[3]=2; a[5]=2; a[7]=2; a[8]=2; b=a.Length; Console.WriteLi ne(b); Console.ReadLin e();
In the example, b will ALWAYS be 10 because that is the Length of the Array you've declared, whether you filled any, some or even none of the elements - they all are initialized to their default type values.
Peter
-- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Madhu" wrote:
I would like to know how the following will be handled in the .net framework: Pl. don't pay attention to the syntax
int a[10] int b
a[1]=2 a[2]=2 a[3]=2 a[5]=2 a[7]=2 a[8]=2
b=a.length % using the in-built function to find the array length
Rest of 'a' is not assigned any valu I get the value of 'b' to be the length of first n values of 'a' which have been initialized, i.e. the array is treated as complete once an uninitialized array element is encountered.
Can someone give me an insight into why this is so?
Thank you.
Thanks Peter. Sorry about the post to the wrong forum. I don't do any
coding work, I'm more a Business side guy. I was trying to help one of
my developers.
Would the length returned be the same even if we are dealing with an
array of objects?
If my question doesn't make sense/is not rigorously stated, never mind
making sense out of it. I'm just putting it the way I understood the
problem.
Thanks
Hi,
Madhu wrote: Thanks Peter. Sorry about the post to the wrong forum. I don't do any coding work, I'm more a Business side guy. I was trying to help one of my developers. Would the length returned be the same even if we are dealing with an array of objects?
If my question doesn't make sense/is not rigorously stated, never mind making sense out of it. I'm just putting it the way I understood the problem.
Thanks
Yes it will. When you create a new array with a given length, the memory
is allocated for this array according to the type of the content. For
objects, the memory is allocated for 10 "handles" (references) to
objects. When you use "Length", it will return 10, even if only 8 cells
are filled up.
HTH,
Laurent This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nathan Rose |
last post by:
Here's my problem. I am reading from a text file using this:
if (!file_exists($file))
{
echo "Don't exist\n";
return false;
}
$fd = @fopen($file, 'r');
if (!is_resource($fd))
|
by: Randell D. |
last post by:
Folks,
Here's my problem:
I am createing an array in a file using the reslut of some PHP and MySQL
processing. An example of my array would be
examlpe="example one";
examlpe="example two";
examlpe="example three";
|
by: Rafi Kfir |
last post by:
Hi,
This may look as a smiple task to most of you, but to me (a beginner
with C), it drives me crazy.
All I want is that one function passes a two dimensional array of
strings to another function.
example:
NOTE: the strings can be of different length and the array will be
|
by: F Da Costa |
last post by:
Hi,
Small question re the use of an Array.
I'v got an array with x rowObjects in it.
When i get it the type of the container is Array and i can get a hold of
the objects just fine.
owever, how do i get the length of the array?
For container.length does not seem to work.
|
by: VK |
last post by:
A while ago I proposed to update info in the group FAQ section, but I
dropped the discussion using the approach "No matter what color the cat
is as long as it still hounts the mice". Over the last month I had
enough of extra proof that the cat doesn't hount mice anymore in more
and more situations. And the surrent sicretisme among array and hash is
the base for it.
I summarized all points in this article:...
| |
by: VK |
last post by:
Whatever you wanted to know about it but always were affraid to ask.
<http://www.geocities.com/schools_ring/ArrayAndHash.html>
|
by: Zordiac |
last post by:
How do I dynamically populate a string array?
I hope there is something obvious that I'm missing here
Option Strict On
dim s() as string
dim sTmp as string = "test"
dim i as integer
s(i)=new string(test)
Above line gives - error implicit conversion string to 1-dim array of
|
by: RyanTaylor |
last post by:
I have a final coming up later this week in my beginning Java class and my
prof has decided to give us possible Javascript code we may have to write.
Problem is, we didn't really cover JS and what we covered was within the
last week of the class and all self taught.
Our prof gave us an example of a Java method used to remove elements from an
array:
public void searchProcess()
{ int outIt=0;
|
by: David Golightly |
last post by:
Quick question for the gurus out there: in ECMAScript, one can create
a new Array object with a length like so:
var animals = new Array(128);
This creates a new Array object with a "length" property set to 128.
My question: Does this in any sense "preallocate" memory for any of
these 128 slots? I've seen the word "preallocate" bandied about, but
my experience with UAs tells me this term is being misused; all 128 of
those "slots"...
|
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: 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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |