Total number of elements in a specified dimension of an Array in C# (original) (raw)
Last Updated : 23 Jan, 2019
Array.GetLongLength(Int32) Method is used to get a 64-bit integer that represents the number of elements in the specified dimension of the Array.Syntax:
public long GetLongLength (int dimension);
Here, dimension is the zero-based dimension of the Array whose length is to be calculated.Return Value: It returns a 64-bit
integer that represents the number of elements in the specified dimension.Exception: This method throws IndexOutOfRangeException if the dimension is less than zero or greater than or equal to Rank.Example:
CSharp `
// C# program to illustrate the // Array.GetLongLength() method using System;
namespace geeksforgeeks {
class GFG {
// Main Method
public static void Main()
{
// Three-dimensional array.
int[,, ] arr = new int[,, ] {
{ { 1, 2, 3 },
{ 4, 5, 6 },
{ 6, 7, 8 }
},
{ { 11, 12, 13 },
{ 14, 15, 16 },
{ 17, 18, 19 }
},
{ { 21, 22, 23 },
{ 24, 25, 26 },
{ 27, 28, 29 }
},
};
Console.Write("Total Number of Elements in"
+ " first dimension of arr: ");
// using GetLongLength Method
Console.Write(arr.GetLongLength(0));
// getting the type of returned value
Console.WriteLine("\nType of returned Length: "
+ (arr.GetLongLength(0)).GetType());
// showing difference between GetLength
// and GetLongLength method by getting
// the type of the both method's
// returned value
Console.Write("\nTotal Number of Elements in "
+ "second dimension of arr: ");
// using GetLength Method
Console.Write(arr.GetLength(1));
// getting the type of returned value
Console.WriteLine("\nType of returned Length: "
+ (arr.GetLength(1)).GetType());
Console.Write("\nTotal Number of Elements in "
+ "second dimension of arr: ");
// using GetLongLength() Method
Console.Write(arr.GetLongLength(1));
// getting the type of returned value
Console.WriteLine("\nType of returned Length: "
+ (arr.GetLongLength(1)).GetType());
}
} }
`
Output:
Total Number of Elements in first dimension of arr: 3 Type of returned Length: System.Int64
Total Number of Elements in second dimension of arr: 3 Type of returned Length: System.Int32
Total Number of Elements in second dimension of arr: 3 Type of returned Length: System.Int64
Note: In the above program, GetLength method return type is System.Int32
but the GetLongLength method return type is System.Int64
.Reference:
Similar Reads
- C# | Total number of elements present in an array Array.GetLength(Int32) Method is used to find the total number of elements present in the specified dimension of the Array. Syntax: public int GetLength (int dimension); Here, dimension is a zero-based dimension of the Array whose length needs to be determined.Return value: The return type of this m 2 min read
- C# | Count the total number of elements in the List List class represents the list of objects which can be accessed by index. It comes under the System.Collection.Generic namespace. List class can be used to create a collection of different types like integers, strings etc. List class also provides the methods to search, sort, and manipulate lists. L 2 min read
- C# | Get or set the number of elements in the BitArray The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on i.e, 1 and false indicates the bit is off i.e, 0. This class is contained in System.Collections namespace. BitArray.Length property is used to get or set the number of 2 min read
- C# | Insert an element into the ArrayList at the specified index ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Insert(Int32, Object) method inserts an element into the ArrayLis 3 min read
- C# | Get the number of elements actually contained in the ArrayList ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Count property gets the number of elements actually contained in 3 min read
- C# | Performing Specified action on each element of Array Array.ForEach(T[], Action) Method is used to perform the specified action on each element of the specified array. Syntax: public static void ForEach (T[] array, Action action); Parameters: array: The one-dimensional, zero-based Array on whose elements the action is to be p 3 min read
- C# | Number of elements contained in the BitArray The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on i.e, 1 and false indicates the bit is off i.e, 0. This class is contained in System.Collections namespace. BitArray.Count property is used to get the number of element 2 min read
- C# | ArrayList whose elements are copies of the specified value ArrayList.Repeat(Object, Int32) Method is used to return an ArrayList whose elements are copies of the specified value. Or in other words, this method is used when you want to repeat a specified element in the ArrayList. This method is an O(n) operation, where n is the number of times item should be 2 min read
- C# | How to insert an element in an Array? An array is a collection of items stored at contiguous memory locations. In this article, we will see how to insert an element in an array in C#. Let's say we have an array and we want to insert an element at a specific position in this array. Here's how to do it. First get the element to be inserte 2 min read
- C# | Get or set the number of elements that the ArrayList can contain ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Capacity property is used to get or set the number of elements th 2 min read