본문 바로가기

Visual Basic.Net

선언시 As New 와 As 그리고 New

일반 자료형 타입에는 new는 사용할 수 없다.


 

Dim objColl1 As New Collection    'Collection Class의 인스턴스 생성

Dim objColl2 As Collection            'Collection이라고만 선언된 상태

 

----------------------------------------------------------------


'Collection 클래스의 Add 라는 함수가 있다고 가정하고...


Dim objColl1 As New Collection

Dim objColl2 As Collection

objColl1.Add "test" 

objColl2.Add "test"     '<-- 오류가 납니다.

 

---------------------------------------------------------------

아래와 같이 사용해야 합니다.

 

Dim objColl1 As New Collection

Dim objColl2 As Collection

objColl1.Add "test" 

Set objColl2 = New Collection   

objColl2.Add "test"