我必须遗漏一些东西 - 没有意义的分号错误

问题描述 投票:1回答:2

这是我的页面的来源。我收到一个神秘的CS1002错误。现在已经看了一段时间,无法弄明白。

<%@ Page language="C#" validateRequest=false %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Threading" %>
<script language="C#" runat="server">

private void Page_Load (object sender, System.EventArgs e)
{
System.IO.Stream str; String strmContents;
Int32 counter, strLen, strRead;
// Create a Stream object.
str = Request.InputStream;
// Find number of bytes in stream.
strLen = Convert.ToInt32(str.Length);
// Create a byte array.
byte[] strArr = new byte[strLen];
// Read stream into byte array.
strRead = str.Read(strArr, 0, strLen);
writeFile(strArr, "images/test.png");
}

 public void writeFile (byte[] data, String fileName)
{
FileStream out = new FileStream(fileName, FileMode.Open);
out.write(data);
out.close();
}

</script>

它抱怨预期会有分号

Compiler Error Message: CS1002: ; expected

Line 24:    FileStream out = new FileStream(fileName, FileMode.Open);
c# arrays filestream
2个回答
8
投票

out是一个关键字,我认为你不能将它用作变量名。而是尝试:

public void writeFile (byte[] data, String fileName)
{
    FileStream fs = new FileStream(fileName, FileMode.Open);
    fs.write(data);
    fs.close();
}

-1
投票

你不能用,因为它是保留关键字。

http://msdn.microsoft.com/en-us/library/t3c3bfhx%28v=vs.71%29.aspx

© www.soinside.com 2019 - 2024. All rights reserved.