
using (fileStream fs = new fileStream(path,fileMode.Open,fileAccess.Read,fileShare.ReaDWrite)) { // do stuff with fs here}// do more stuff after 如果fileStream构造函数返回null(如果fileStream构造函数总是返回一个有效的对象,让我们只是为了参数说可以返回null),那么代码内部会执行吗?或者它会跳过“在这里用fs做什么”代码?
解决方法using (fileStream fs = new fileStream(path,fileShare.ReaDWrite)) { // do stuff with fs here}// do more stuff after 相当于:
fileStream fs = new fileStream(path,fileShare.ReaDWrite)try{ // do stuff with fs here}finally{ if (fs != null) { ((Idisposable)fs).dispose(); }}// do more stuff after 所以回答你的问题:
If the fileStream constructor were to return null (if the fileStream
constructor always returns a valID object,let’s just say for sake of
argument that it is possible to return null),would the code insIDe
execute?
是的,它会的.
显然,每个熟悉C#规范的人都知道构造函数(无论哪种类型)永远不能返回null,这使得你的问题变得有点不切实际.
总结以上是内存溢出为你收集整理的当c#.net使用块失败时会发生什么?全部内容,希望文章能够帮你解决当c#.net使用块失败时会发生什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)