Array Length

From SwiftAPI

Jump to: navigation, search

Contents

C++

For vectors:

#include <vector>
using namespace std;
 
int a0[] = {0, 2, 4, 6, 8};
vector<int> a(a0, a0+5);
int n = a.size();
// n == 5

C#

int[] a = new int[] { 0, 2, 4, 6, 8 };
int n = a.Length;
// n == 5

Java

For arrays:

int[] a = {0, 2, 4, 6, 8};
int n = a.length;
// n == 5

For Lists:

import java.util.Arrays;
 
List<Integer> a = Arrays.asList(0, 2, 4, 6, 8);
int n = a.size();
// n == 5

JavaScript

developer.mozilla.org

var a = [0, 2, 4, 6, 8];
var n = a.length;
// n == 5

Objective-C

developer.apple.com

@property(readonly) NSUInteger count
NSArray *a = @[@0, @2, @4, @6, @8];
int n = a.count;
// n == 5

Perl

@a = (0, 2, 4, 6, 8);
$n = @a;
# $n == 5

PHP

php.net

$a = array(0, 2, 4, 6, 8);
$n = count($a);
// $n == 5

Python

a = [0, 2, 4, 6, 8]
n = len(a)
# n == 5

Ruby

ruby-doc

array.length => int
a = [0, 2, 4, 6, 8]
n = a.length
# n == 5

Swift

let a = [0, 2, 4, 6, 8]
let n = a.count
// n == 5

Visual Basic .NET

Dim a() As Integer = New Integer() {0, 2, 4, 6, 8}
Dim n As Integer = a.Length
' n = 5
Personal tools