如何解决强制转换异常处理问题 [英] how to resolve the cast exception handling
本文介绍了如何解决强制转换异常处理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将一个文件上传到ftp服务器(驱动器hq)。但是发生了一个例外..那就是
无法将System.Net.HttpWebRequest类型的对象强制转换为System.Net.FtpWebRequest。
i can upload one file to ftp server(drive hq).but one exception is occured ..that is
"Unable to cast object of type 'System.Net.HttpWebRequest' to type 'System.Net.FtpWebRequest'."
推荐答案
简单:不要转换类型不赋值兼容。查看两个类的代码和MSDN帮助,它显示继承树中最近的类之间的继承;然后你很好看。如果没有,请学习继承,编译时和运行时类型以及OOP和.NET中的一般输入原则。
-SA
Simple: don't cast types which are not assignment-compatible. Look at your code and the MSDN help on both classes where it shows inheritance between nearest classes in inheritance tree; then you well see it. If not, learn inheritance, compile-time and runtime types and general typing principles in OOP and .NET.
—SA
这篇关于如何解决强制转换异常处理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文