C#의 UInt16.ToString() 메서드는 현재 UInt16 인스턴스의 숫자 값을 해당하는 문자열 표현으로 변환하는 데 사용됩니다.
구문
다음은 구문입니다 -
public override string ToString();
예시
이제 UInt16.ToString() 메서드를 구현하는 예를 살펴보겠습니다. -
using System;
public class Demo {
public static void Main(){
ushort val1 = 100;
ushort val2 = 80;
Console.WriteLine("Value1 (String representation) = "+val1.ToString());
Console.WriteLine("Value2 (String representation) = "+val2.ToString());
bool res = val1.Equals(val2);
Console.WriteLine("Return value (comparison) = "+res);
if (res)
Console.WriteLine("val1 = val2");
else
Console.WriteLine("val1 != val2");
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
Value1 (String representation) = 100 Value2 (String representation) = 80 Return value (comparison) = False val1 != val2
예시
이제 UInt16.ToString() 메서드를 구현하는 또 다른 예를 살펴보겠습니다. -
using System;
public class Demo {
public static void Main(){
ushort val1 = 0;
ushort val2 = UInt16.MaxValue;
Console.WriteLine("Value1 (String representation) = "+val1.ToString());
Console.WriteLine("Value2 (String representation) = "+val2.ToString());
bool res = val1.Equals(val2);
Console.WriteLine("Return value (comparison) = "+res);
if (res)
Console.WriteLine("val1 = val2");
else
Console.WriteLine("val1 != val2");
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
Value1 (String representation) = 0 Value2 (String representation) = 65535 Return value (comparison) = False val1 != val2