[英]C# Store type in an array
I want to store an error in an array, but when I try this it tells me我想在数组中存储一个错误,但是当我尝试这个时它告诉我
System.IO.DirectoryNotFoundException is a type, which is not valid in the given context. System.IO.DirectoryNotFoundException 是一种类型,在给定的上下文中无效。
Type[] errorArray = new Type[] { System.IO.DirectoryNotFoundException };
Am I doing something wrong, or is it not possible this way?我做错了什么,还是不可能这样?
What you want to do is use typeof().你想要做的是使用 typeof()。
Type[] errorArray = new Type[] { typeof(System.IO.DirectoryNotFoundException) };
This way you store the type of your exception.这样您就可以存储异常的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.