任何人都可以帮我解决这些错误吗? [英] can anyone pls hlp me solve these errors?

查看:78
本文介绍了任何人都可以帮我解决这些错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;

namespace Default
{

protected void btnCreate_Click(object sender, EventArgs e)
{
string path = "D:\\MyTest.txt";
if (!File.Exists(path))
{
string() createText = { "Hello","Reading and writing text file" };
File.WriteAllLines(path, createText);
}
string appendText = "This is extra text" + Environment.NewLine;
File.AppendAllText(path, appendText);
lbltxt.Text = "File Created Successfully";
}
protected void btnRead_Click(object sender, EventArgs e)
{
string path = fileupload1.PostedFile.FileName;
if(!string.IsNullOrEmpty(path))
{
string() readText = File.ReadAllLines(path);
StringBuilder strbuild = new StringBuilder();
foreach (string s in readText)
{
strbuild.Append(s);
strbuild.AppendLine();
}
textBoxContents.Text = strbuild.ToString();
}















错误是:

预期的枚举,课程,代表或结构

预期的枚举,课程,委托或结构

预期的枚举,类,委托或结构








the errors are:
Expected enum,class,delegate or struct
Expected enum,class,delegate or struct
Expected enum,class,delegate or struct

推荐答案

您创建数组的语法是错误的。你必须使用 [] ,而不是()

Your syntax of creating arrays is wrong. You have to use [], not ():
string[] createText = { "Hello", "Reading and writing text file" };



此外,您似乎将方法直接放在命名空间中。你不能这样做;方法必须放在一个类中。我想你的意思是将它们放在你的web表单的类中(使用命名空间查看,看起来你使用web表单)。


Also, it appears that you are putting methods directly in a namespace. You cannot do that; methods have to be put in a class. I suppose you meant to put them in the class of your web form (looking at your using namespaces it appears that you use web forms).


这篇关于任何人都可以帮我解决这些错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆