int를 특정 형식으로 변환 한 다음 변환 한 형식에 따라 형식이 다른 문자열을 반환하려고합니다.
Type 개체를 반환하는 속성 및 형식에 따라 형식이 다른 문자열을 반환 할 속성이 있습니다.
왜 HexString의 코드가 컴파일러와 비슷하지 않습니까?
똑같이 간단한 방법이 있습니까?C# ChangeType 및 ToString?
public class TestClass
{
private int value;
public bool signed;
public int nBytes;
public int Value { get {return value;} set {this.value = value;}}
public Type Type {
get {
switch (this.nBytes) {
case 1:
return (this.signed ? typeof(SByte) : typeof(Byte));
case 2:
return (this.signed ? typeof(Int16) : typeof(UInt16));
default:
return null;
}
}
}
public String HexString {
get {
//?? compiler error: "no overload for method 'ToString' takes '1' arguments
return (Convert.ChangeType(this.Value, this.Type)).ToString("X" + this.nBytes);
}
}
}
이것은 대답이 아닙니다. 단지 제안입니다. 제네릭을 사용하면 도움이 될지도 모릅니다. –