This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- Ada
- C
- C
- Clojure
- C++
- C#
- C#
- D
- D
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Groovy
- Haskell
- JS
- Java
- Java
- Kotlin
- Lisp
- Lua
- Obj-C
- PHP
- Pascal
- Perl
- Perl
- Prolog
- Python
- Ruby
- Rust
- Scala
- Scheme
- Smalltalk
- VB
- VB
int n;
int x[5];
n = sizeof(x)/sizeof(*x);
C doesn't have the higher level concept of lists at least as many may understand it, so this completes the prompt using C arrays. sizeof(array) will return the amount of bytes all the elements of the array are taking up and sizeof(var) will return the amount of bytes a single variable is taking up. *x in this example is the same as x[0]; it retrieves the first element of the array, so we're dividing the amount of bytes total for the array by the amount of bytes each element uses.
int n = x.Count;
Works for a List object.
If x is of type IEnumerable, use Count() instead.
If x is of type IEnumerable, use Count() instead.
n = walkLength(x);
walkLength is a generic solution that works for built-in arrays and containers that implement an input range interface.
$n = count($x);
PHP lacks a native list container, instead it uses a container called an "array" that is actually an ordered map.
$n = scalar @x;
This is a recommended way, which ensures that any kind of list is in scalar mode, where only it's size is produced.
Dim n As Integer = x.Count
The general list interface IList(Of T) inherits its Count property from ICollection(Of T)
programming-idioms.org