最初は動作していますが、2番目にエラーが表示されますが、違いは何ですか? 私はドキュメントを読んで、それについて何かを見つける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
@ TheLethalCoder var z =(A)q; ここにエラーがあります。私が見ることができるように、タイプA – GodlikeRabbit