첫 번째 오류는 작동하지만 두 번째 오류는 보여 주지만 차이점은 무엇입니까? 나는 문서를 읽고, 그것에 대해 아무것도 찾을 didnt는, 그렇게 중요하지 만 일부 기능C에서 명시 적 변환과 안전한 캐스팅의 차이점 #
public static string GetConcat2<T>(T q)
{
if(q.GetType() == typeof(A))
{
var z = q as A;
}
if (q.GetType() == typeof(A))
{
var z = (A)q;
}
return "!!!!";
}
public interface CustomInteface
{
string InterfaceProperty1 { get; set; }
string InterfaceProperty2 { get; set; }
string Concat();
}
public class A : CustomInteface
{
public string InterfaceProperty1 { get; set; }
public string InterfaceProperty2 { get; set; }
public string Concat() {
return InterfaceProperty1 + InterfaceProperty2;
}
}
오류 란 무엇입니까? 오류는 어디에서 발생합니까? 문제를 재현하는 데 필요한 모든 정보와 코드를 제공하려고 시도하십시오. [MCVE]를 포함하십시오. – TheLethalCoder
@ TheethalCoder var z = (A) q; 예 여기가 유, 내가 제네릭 형식을 확인하고 있습니다 볼 수 있습니다 같이 – GodlikeRabbit