비주얼 베이직 닷넷과 C 샤프의 비교

위키백과, 우리 모두의 백과사전.

C#비주얼 베이직 닷넷닷넷 프레임워크에서 사용되는 두 개의 주된 언어이다.

언어 적합성[편집]

C#는 구문 유사성을 자바와 공유한다. C#와 비주얼베이직 닷넷 모두 현대적 고급 언어인 자바와 C++는 구조상의 유사성을 지닌다. 그러나 자바와 닷넷의 차이점은 많으며, 자바와 C 샤프의 비교에서 볼 수 있다.

런타임 다중 언어 지원[편집]

닷넷의 주요 목표 중 하나는 다중 언어 지원이다. 디자인의 목적은 모든 마이크로소프트 언어는 모든 운영 체제 특징으로 같은 단계의 엑세스를 가져야 하고 같은 단계의 힘과 유용성과 다른 언어에서 쓰여진 모듈로부터 간단한 요청을 보여 주어야 한다는 것이다. 모든 닷넷 프로그램 언어는 같은 런타임 엔진과 동일한 추상 구문 트리공통 중간 언어를 공유한다. 게다가 모든 닷넷 언어는 가비지 컬렉션과 교차 언어 상속, 예외 처리디버깅을 포함한 플랫폼 특징에 엑세스할 수 있다. 이것은 다른 닷넷 언어로부터 생산된 바이너리는 같음을 허락한다.

개발 환경[편집]

비주얼 스튜디오는 C#과 VB.Net의 개발 환경의 몇몇 차이점을 대비한다.비주얼 스튜디오가 발표됨으로써, 이 개발 환경 간의 차이는 줄여졌다. 예를 들면 초기의 비주얼 스튜디오는 C#을 비주얼 베이직으로 변환하는 지원이 매우 좋지 않았고 C#에 대한 백그라운드 변환을 제공하지 않았다.[1].

하지만, 비주얼 베이직 6에서 비주얼 베이직 닷넷으로 되면서 다음과 같은 특징이 더해졌다.

  • 기본 네임스페이스는 숨겨짐(해제 가능)
  • 몇몇 프로젝트 파일은 숨길 수 있음(사용자가 보이게 할 수 있음)

C#에 없는 비주얼 베이직 닷넷의 특징[편집]

  • 변수를 WithEvents 구조체를 사용하여 선언할 수 있다. 이 구조는 프로그래머는 '클래스 이름' 목록에서 개체를 선택할 수 있도록 선언에서 메서드를 선택하고 자동 삽입 메서드 서명을 가진 목록을 사용할 수 있도록 한다
  • 이벤트의 자동 wireup에 의해, 비주얼 베이직 닷넷은 이벤트에 대한 핸들 구문을 가지고 있다

비주얼 베이직 닷넷에 없는 C#의 특징[편집]

  • unsafe 키워드로 안전하지 않는 코드의 블록(C++/CLI 같이)을 허용한다.
  • 불완전한 인터페이스
  • 반복자와 yield 키워드
  • 멀티 라인 주석(비주얼 스튜디오 IDE는 Visual Basic .NET의 멀티 라인 주석을 지원한다.)
  • 정적 클래스(클래스는 비정적 클래스를 포함할 수 없다, although VB's Modules are essentially sealed static classes with additional semantics)

키워드[편집]

비주얼 베이직은 대소문자를 구별하지 않으며 이것은 키워드에서 어떠한 대소문자 조합도 받아들여짐을 의미한다. 하지만 비주얼 스튜디오는 자동으로 모든 비주얼 베이직 키워드를 일반적인 대소문자 형태로 맞춰준다. (예: "Public", "If")

C#은 대소문자를 구별하며 모든 C# 키워드는 소문자로만 이루어져 있다.

비주얼 베이직과 C#은 대부분의 키워드를 공유한다. 비주얼 베이직의 키워드들은 대소문자 형태가 갖추어진 C# 키워드이다. (예: "Public"과 "public", "If"와 "if")

주석 사용[편집]

C# Visual Basic .NET
//한줄 주석
/*여러줄 주석
  line 2
  line 3*/

///XML 한줄 주석

/**XML 여러줄 주석
   line 2
   line 3*/
'한줄 주석

두줄 이상의 주석은 불가능

'''XML 한줄 주석

두줄 이상의 주석은 불가능

조건식[편집]

C# Visual Basic .NET
if (condition)
{
    // condition is true
}
If condition Then
    ' condition is true
End If
if (condition)
{
    // condition is true
}
else
{
    // condition is false
}
If condition Then
    ' condition is true
Else
    ' condition is false
End If
if (condition)
{
    // condition is true
}
else if (othercondition)
{
    // condition is false and othercondition is true
}
If condition Then
    ' condition is true
ElseIf othercondition Then
    ' condition is false and othercondition is true
End If
if (condition)
{
    // condition is true
}
else if (othercondition)
{
    // condition is false and othercondition is true
}
else
{
    // condition and othercondition are false
}
If condition Then
    ' condition is true
ElseIf othercondition Then
    ' condition is false and othercondition is true
Else
    ' condition and othercondition false
End If

루프[편집]

C# Visual Basic .NET
for (int i = 0; i <= number - 1; i++)
{
    // loop from zero up to one less than number
}
For i = 0 To number - 1
    ' loop from zero up to one less than number
Next i
for (int i = number; i >= 0; i--)
{
    // loops from number down to zero
}
For i = number To 0 Step -1
    ' loops from number down to zero
Next i
break; //breaks out of a loop
Exit For 'breaks out of a for loop
Exit While 'breaks out of a while loop
Exit Do 'breaks out of a do loop

비교[편집]

원시 타입[편집]

C# Visual Basic .NET
if (a == b)
{
    // equal
}
If a = b Then
    ' equal
End If
if (a != b)
{
    // not equal
}

Or:

if (!(a == b))
{
    // not equal
}
If a <> b Then
    ' not equal
End If

Or:

If Not a = b Then
    ' not equal
End If
if (a == b && c == d || e == f)
{
    // multiple comparisons
}
If a = b And c = d Or e = f Then
    ' multiple comparisons
End If
if (a == b && c == d || e == f)
{
    // short-circuiting comparisons
}
If a = b AndAlso c = d OrElse (e = f) Then
    ' short-circuiting comparisons
End If

개체 유형[편집]

C# Visual Basic .NET
if (Object.ReferenceEquals(a, b))
{
    // variables refer to the same instance
}
If a Is b Then
    ' variables refer to the same instance
End If
if (!Object.ReferenceEquals(a, b))
{
    // variables do not refer to the same instance
}
If a IsNot b Then
    ' variables do not refer to the same instance
End If
if (a.Equals(b))
{
    // 인스턴트가 동등하다.
}
If a = b Then
    ' 인스턴트가 동등하다.
End If
if ( ! a.Equals(b))
{
    // 인스턴트가 동등하지 않다.
}
If a <> b Then
    ' 인스턴트가 동등하지 않다.
End If
var type = typeof(int);
Dim type = GetType(Integer)
if (a is b)
{
    // types of a and b are compatible
}
If TypeOf a Is b Then
    ' types of a and b are compatible
End If
if (!(a is b))
{
    // types of a and b are not compatible
}
If Not TypeOf a Is b Then
    ' types of a and b are not compatible
End If
C#
if(object.equals(a,b))
VB.NET
If a = b Then
// converting from Gregorian to Persian date
Persia.Calendar.ConvertToPersian(DateTime dateTime);
Persia.Calendar.ConvertToPersian(int year, int month, int day, Persia.DateType.Gerigorian);

// converting from Islamic to Persian date
Persia.Calendar.ConvertToPersian(Persia.MoonDate moonDate);
Persia.Calendar.ConvertToPersian(int year, int month, int day, Persia.DateType.Islamic);

zx1[편집]

  1. Matthew Gertz. “Scaling Up: The Very Busy Background Compiler”. MSDN Magazine. 2008년 2월 19일에 원본 문서에서 보존된 문서. 2008년 12월 16일에 확인함. 
N mm mm  2   .ry up I

외부 링크[편집]