C# | LongLength property of an Array (original) (raw)
Last Updated : 23 Jan, 2019
Array.LongLength Property is used to get a 64-bit integer that represents the total number of elements in all the dimensions of the Array.Syntax:
public long LongLength { get; }
Property Value: This property returns a 64-bit integer that represents the total number of elements in all the dimensions of the Array.Example:
CSharp `
// C# program to illustrate the // Array.LongLength Property using System; namespace geeksforgeeks {
class GFG {
// Main Method
public static void Main()
{
// Two-dimensional array
int[, ] intarray = new int[, ] { { 1, 2 },
{ 3, 4 },
{ 5, 6 },
{ 7, 8 } };
// The same array with dimensions
// specified 4 row and 2 column.
int[, ] intarray_d = new int[4, 2] { { 1, 2 },
{ 3, 4 },
{ 5, 6 },
{ 7, 8 } };
Console.Write("Total Number of Elements in intarray: ");
// using LongLength property
Console.Write(intarray.LongLength);
// getting the type of returned value
Console.WriteLine("\nType of returned Length: "
+ (intarray.LongLength).GetType());
// showing difference between Length
// and LongLength property by getting
// the type of the both property's
// returned value
Console.Write("\nTotal Number of Elements in intarray_d: ");
// using Length property
Console.Write(intarray_d.Length);
// getting the type of returned value
Console.WriteLine("\nType of returned Length: "
+ (intarray_d.Length).GetType());
Console.Write("\nTotal Number of Elements in intarray_d: ");
// using LongLengthLength property
Console.Write(intarray_d.LongLength);
// getting the type of returned value
Console.WriteLine("\nType of returned Length: "
+ (intarray_d.LongLength).GetType());
}
} }
`
Output:
Total Number of Elements in intarray: 8 Type of returned Length: System.Int64
Total Number of Elements in intarray_d: 8 Type of returned Length: System.Int32
Total Number of Elements in intarray_d: 8 Type of returned Length: System.Int64
Note: In the above program you can see that Array.Length
property always returns the length of the type System.Int32 but Array.LongLength
property always returns the length of the type System.Int64.Reference:
Similar Reads
- How to find the length of an Array in C# Array.Length Property is used to get the total number of elements in all the dimensions of the Array. Basically, the length of an array is the total number of the elements which is contained by all the dimensions of that array. Syntax: public int Length { get; } Property Value: This property returns 3 min read
- 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
- Total number of elements in a specified dimension of an Array in C# 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 2 min read
- C# | Check if an Array has fixed size or not Array.IsFixedSize Property is used to get a get a value indicating whether the Array has a fixed size. This property implements the IList.IsFixedSize Property . Syntax: public bool IsFixedSize { get; } Property Value: This property is always return true for all arrays. Below programs illustrate the 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# Jagged Arrays A jagged array is an array of arrays, where each element in the main array can have a different length. In simpler terms, a jagged array is an array whose elements are themselves arrays. These inner arrays can have different lengths. Can also be mixed with multidimensional arrays. The number of rows 4 min read
- C# | Sets the capacity to the actual number of elements in the ArrayList ArrayList.TrimToSize Method is used to set the capacity to the actual number of elements in the ArrayList. It can be used to minimize a collection's memory overhead if no new elements will be added to the collection. Note: This method is an O(n) operation, where n is Count. Syntax: public virtual vo 3 min read
- C# Array Class Array class in C# is part of the System namespace and provides methods for creating, searching, and sorting arrays. The Array class is not part of the System.Collections namespace, but it is still considered as a collection because it is based on the IList interface. The Array class is the base clas 7 min read
- C# Arrays An array is a group of like-typed variables that are referred to by a common name. And each data item is called an element of the array. The data types of the elements may be any valid data type like char, int, float, etc. and the elements are stored in a contiguous location. Length of the array spe 8 min read
- long keyword in C# Keywords are the words in a language that are used for some internal process or represent some predefined actions. long is a keyword that is used to declare a variable which can store a signed integer value from the range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. It is an alias of 2 min read