Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Im using array.GetLength() method in c#. Its asking for array dimension as a parameter.does it start at 1 or 0?
It's just a 1 dimensional array, but would it be dimension 1, or dimension 0?
2 Answers
- 1 decade agoFavorite Answer
To find out the length of an array---> int l = array.length;
To find the last item of an array---> string last = somearray[somearray.Length-1];
You can use ArrayList. ArrayList will not check for errors at compile time.
To declare list---> ArrayList myList = new ArrayList();
To add something---->myList.Add(....);
then you can loop through an ArrayList like this:
foreach (object obj in myList)
{
if(obj is string)
{do this...)
else if(obj is DateTime)
{do this....}
else if(obj is bool)
{do this....}
else if(obj is Int)
{do this....}
else
{
// always have an else in case it falls through
throw new Exception();
}
}
Generic List is better choice--->List<Object> myObjectList = new List<Object>();
because array list will not throw an error at compile time, but generic list will because it checks for errors at compile time.
Length of an array starts at 0 index.
My suggestion is to use stack overflow where you can get answers pretty fast.
- RatchetrLv 71 decade ago
It would be 0.
An easier way is to just write:
length = array.Length;
Length gives you the total number of elements in the array. For a 1 dimensional array, Length and GetLength(0) are identical.