我有这样的代码Java,我用来报告异常(抛出FileNotFoundException,IOException,ClassNotFoundException).
例:
private void functionName() throws FileNotFoundException, IOException, ClassNotFoundException{}
Run Code Online (Sandbox Code Playgroud)
我需要这样做C#,我该怎么做?
这很简单。在C#中,不能直接使用throws语句,因为没有\xc2\xb4t。您可能想使用此代码:
private void functionName(){ throw new IOException();}\nRun Code Online (Sandbox Code Playgroud)\n\n这会引发 IOException。由于 IOException 是一个类,因此您需要创建一个新的类,并带有new语句。