UShort 데이터 형식 (Visual Basic)UShort data type (Visual Basic)
0에서 65535 사이의 값에 해당 하는 부호 없는 16 비트 (2 바이트) 정수를 저장 합니다.Holds unsigned 16-bit (2-byte) integers ranging in value from 0 through 65,535.
설명Remarks
UShort
에 대해 너무 크지 않은 이진 데이터를 포함 하려면 데이터 형식을 사용 Byte
합니다.Use the UShort
data type to contain binary data too large for Byte
.
UShort
의 기본값은 0입니다.The default value of UShort
is 0.
리터럴 할당Literal assignments
UShort
10 진수 리터럴, 16 진수 리터럴, 8 진수 리터럴 또는 (Visual Basic 2017부터) 이진 리터럴을 할당 하 여 변수를 선언 하 고 초기화할 수 있습니다.You can declare and initialize a UShort
variable by assigning it a decimal literal, a hexadecimal literal, an octal literal, or (starting with Visual Basic 2017) a binary literal. 정수 리터럴이 UShort
범위를 벗어나는 경우(즉 UInt16.MinValue보다 작거나 UInt16.MaxValue보다 큰 경우) 컴파일 오류가 발생합니다.If the integer literal is outside the range of UShort
(that is, if it is less than UInt16.MinValue or greater than UInt16.MaxValue, a compilation error occurs.
다음 예제에서는 10 진수, 16 진수 및 이진 리터럴로 표현 된 65034와 동일한 정수가 값에 할당 됩니다 UShort
.In the following example, integers equal to 65,034 that are represented as decimal, hexadecimal, and binary literals are assigned to UShort
values.
Dim ushortValue1 As UShort = 65034
Console.WriteLine(ushortValue1)
Dim ushortValue2 As UShort = &HFE0A
Console.WriteLine(ushortValue2)
Dim ushortValue3 As UShort = &B1111_1110_0000_1010
Console.WriteLine(ushortValue3)
' The example displays the following output:
' 65034
' 65034
' 65034
참고
접두사 또는를 사용 하 여 &h
&H
16 진수 리터럴을 표시 하거나, 접두사 또는을 사용 하 여 이진 리터럴을 표시 하 고, 접두사 또는를 사용 하 여 &b
&B
&o
&O
8 진수 리터럴을 나타냅니다.You use the prefix &h
or &H
to denote a hexadecimal literal, the prefix &b
or &B
to denote a binary literal, and the prefix &o
or &O
to denote an octal literal. 10진수 리터럴에는 접두사가 없습니다.Decimal literals have no prefix.
Visual Basic 2017부터 _
다음 예제와 같이 밑줄 문자를 자릿수 구분 기호로 사용 하 여 가독성을 높일 수도 있습니다.Starting with Visual Basic 2017, you can also use the underscore character, _
, as a digit separator to enhance readability, as the following example shows.
Dim ushortValue1 As UShort = 65_034
Console.WriteLine(ushortValue1)
Dim ushortValue3 As UShort = &B11111110_00001010
Console.WriteLine(ushortValue3)
' The example displays the following output:
' 65034
' 65034
Visual Basic 15.5부터 _
접두사와 16 진수, 이진 또는 8 진수 숫자 사이의 선행 구분 기호로 밑줄 문자 ()를 사용할 수도 있습니다.Starting with Visual Basic 15.5, you can also use the underscore character (_
) as a leading separator between the prefix and the hexadecimal, binary, or octal digits. 예를 들면 다음과 같습니다.For example:
Dim number As UShort = &H_FF8C
선행 구분 기호로 밑줄 문자를 사용하려면 Visual Basic 프로젝트(*.vbproj) 파일에 다음 요소를 추가해야 합니다.To use the underscore character as a leading separator, you must add the following element to your Visual Basic project (*.vbproj) file:
<PropertyGroup>
<LangVersion>15.5</LangVersion>
</PropertyGroup>
자세한 내용은 Visual Basic 언어 버전 설정을참조하십시오.For more information see setting the Visual Basic language version.
US
다음 예제와 같이 숫자 리터럴은 또는 us
형식 문자 를 포함 하 여 데이터 형식을 나타낼 수도 있습니다 UShort
.Numeric literals can also include the US
or us
type character to denote the UShort
data type, as the following example shows.
Dim number = &H_5826us
프로그래밍 팁Programming tips
음수.Negative Numbers.
UShort
는 부호 없는 형식이 기 때문에 음수를 나타낼 수 없습니다.BecauseUShort
is an unsigned type, it cannot represent a negative number.-
형식을 반환 하는 식에 단항 빼기 () 연산자를 사용 하는 경우UShort
Visual Basic는 식을Integer
먼저 변환 합니다.If you use the unary minus (-
) operator on an expression that evaluates to typeUShort
, Visual Basic converts the expression toInteger
first.CLS 규격.CLS Compliance.
UShort
데이터 형식이 cls ( 공용 언어 사양 )의 일부가 아니므로 cls 규격 코드는이를 사용 하는 구성 요소를 사용할 수 없습니다.TheUShort
data type is not part of the Common Language Specification (CLS), so CLS-compliant code cannot consume a component that uses it.넓혀.Widening.
UShort
데이터 형식은,,,,, 및로 확대 변환Integer
UInteger
Long
ULong
Decimal
Single
Double
됩니다.TheUShort
data type widens toInteger
,UInteger
,Long
,ULong
,Decimal
,Single
, andDouble
. 즉,UShort
오류가 발생 하지 않고 이러한 형식으로 변환할 수 있습니다 System.OverflowException .This means you can convertUShort
to any of these types without encountering a System.OverflowException error.문자를 입력 합니다.Type Characters. 리터럴 형식 문자를 리터럴에 추가 하면
US
UShort
데이터 형식이 됩니다.Appending the literal type charactersUS
to a literal forces it to theUShort
data type.UShort
에는 식별자 형식 문자가 없습니다.UShort
has no identifier type character.Framework 형식.Framework Type. .NET Framework에서 해당하는 형식은 System.UInt16 구조체입니다.The corresponding type in the .NET Framework is the System.UInt16 structure.