"함수 is array()"의 두 판 사이의 차이

69번째 줄: 69번째 줄:
End Function
End Function


Dim col As New Collection
'Dim col As New Collection
Dim str As String
'Dim str As String
   
'MsgBox IsCollection(col) 'True
MsgBox IsCollection(col) 'True
'MsgBox IsCollection(str) 'False
MsgBox IsCollection(str) 'False
</source>
</source>



2014년 11월 7일 (금) 18:33 판

is_array
isArray
  • (boolean) Determine whether the argument is an array

1 C#

public static bool is_array(object obj) 
{
  return obj.GetType().IsArray;
}
int [] array = {1,2,3,4};
Console.WriteLine("Is this type an array? {0}", array.GetType().IsArray);

2 JavaScript

function is_array(input){ return typeof(input)=='object'&&(input instanceof Array); }
var bar = 1;
var foo = [1];
console.log(is_array(bar)); // false
console.log(is_array(foo)); // true

3 jQuery

var bar = 1;
var foo = [1];
console.log($.isArray(bar)); // false
console.log($.isArray(foo)); // true

4 Objective-C

// NSArray or NSMutableArray → true
-(bool)is_array:(NSObject*)obj {
  return [obj isKindOfClass:[NSArray class]];
}

5 PHP

// true
echo is_array( array(1, 2, 3) );

// false
echo is_array( '1, 2, 3' );

6 VBA

Function IsCollection(ByVal obj) As Boolean
    On Error Resume Next
    Dim element As Variant
    IsCollection = True
    For Each element In obj
        If Err Then IsCollection = False
        Exit For
    Next
    Err.Clear
End Function

'Dim col As New Collection
'Dim str As String
'MsgBox IsCollection(col) 'True
'MsgBox IsCollection(str) 'False

7 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}