using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection.Emit;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
string[] strETypes = {"没有", "类型1", "类型2", "类型3"}; foreach (string strEType in strETypes)
{
ThrowException(strEType);
} try
{
}
catch
{
}
finally
{
}
}
}
}错误C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\HelloWorld.exe /target:exe Program.cs Properties\AssemblyInfo.cs
G:\CENJINLONG\CSharp\HelloWorld\HelloWorld\Program.cs(17,17): 错误 CS0103: 当前上下文中不存在名称“ThrowException”
如果是抛出异常,应该是用throw new xxx("message");的方式,这里xxx是Exception或者继承于Exception的类;
如果是调用ThrowException方法,那么你必须要有这个方法的定义,比如:void ThrowException()
{
// 这里填写你的代码
}
根据你说的情况,肯定你没有把示例代码中的ThrowException方法加入到你的代码中,所以就编译没法通过。