问一个关于foreach的小问题
我写了如下代码:
<%@ Page Language= "C# " AutoEventWireup= "True " %>
<% @Import Namespace= "System.IO " %>
<html>
<head>
<script language= "C# " runat= "server ">
string[] drives = Directory.GetLogicalDrives();
int i=0;
foreach (string str in drives)
{
System.Console.WriteLine(str);
}
</script>
</head>
<body>
<form runat=server>
<h3> LinkButton Example </h3>
<asp:LinkButton id= "LinkButton1 "
Text= "Click Me "
Font-Name= "Verdana "
Font-Size= "14pt "
OnClick= "LinkButton_Click "
runat= "server "/>
<p>
<asp:Label id=Label1 runat=server /> <br>
<asp:Label id=Label2 runat=server />
</form>
</body>
</html>
可是在执行时总会提示:
类、结构或接口成员声明中的标记“foreach”无效
请问这是为什么?
------解决方案--------------------foreach (string str in drives)
{
System.Console.WriteLine(str);
}
---------------------------------
foreach (string str in drives)
{
Response.Write(str);
}