标题:C#类、结构或接口成员声明中的标记“(”无效
只看楼主
waxiaoguai
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-1
结帖率:0
已结贴  问题点数:20 回复次数:3 
C#类、结构或接口成员声明中的标记“(”无效
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using

namespace 文件
{
    public partial class Form1 : Form

      {      int []a=new int [10];
  
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = "aa.txt"; 
             string mystr = "";
            FileStream fs = File.OpenRead(path);
             StreamReader sr = new StreamReader(fs, Encoding.Default );
            //指定打开文件
            string str;
            int max=0;
            while ((str =sr .ReadLine())!=null )
            {
                mystr = mystr + str + "\r\n";  //\r\n表示回车换行
               int t=0;
                t=Convert .ToInt16 (str );
                if(max<t )
                    max =t ;
            }
                sr.Close();
                fs.Close();
                richTextBox1.Text = mystr;
           textBox1 .Text  =max.ToString();

        }

        private void button2_Click(object sender, EventArgs e)
        {
             Random rdm = new Random();
            bool flag;
            for (int i = 0; i < 10; i++)
            {
                while (true)
                {
                    t = rdm.Next(0, 101);
                    flag = true;
                    for (int j = 0; j < i - 1; j++)
                        if (a[j] == t) flag = false;
                    if (flag == true) break;
                }
                a[i] = t;
            }
            int max = 0;
            for (int i = 1; i < 10; i++)
            {  
                richTextBox1.Text += a[i].ToString() + "\r\n";
               if (max < a[i])
                max =  a[i];
             }
             textBox1 .Text  = max.ToString();
        }

        string pa = "aa.txt";
        FileStream fr = new FileStream("aa.txt", FileMode.Append);
        StreamWriter sr = new StreamWriter(fr, Encoding.Default);
        sr.WriteLine( richTextBox1.Text );//C#类、结构或接口成员声明中的标记“(”无效
        sr.Close();
        fs.Close();

        }
    }




        
   

        
搜索更多相关主题的帖子: private 
2011-06-01 11:21
fily1314
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:166
专家分:1190
注 册:2007-7-18
得分:7 
        string pa = "aa.txt";
        FileStream fr = new FileStream("aa.txt", FileMode.Append);
        StreamWriter sr = new StreamWriter(fr, Encoding.Default);
        sr.WriteLine( richTextBox1.Text );//C#类、结构或接口成员声明中的标记“(”无效
        sr.Close();
        fs.Close();
这段代码放错位置了,放在函数里面。
2011-06-01 11:46
as0
Rank: 2
等 级:论坛游民
帖 子:12
专家分:59
注 册:2010-9-16
得分:7 
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using

namespace 文件
{
    public partial class Form1 : Form

      {      int []a=new int [10];
  
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = "aa.txt"; 
             string mystr = "";
            FileStream fs = File.OpenRead(path);
             StreamReader sr = new StreamReader(fs, Encoding.Default );
            //指定打开文件
            string str;
            int max=0;
            while ((str =sr .ReadLine())!=null )
            {
                mystr = mystr + str + "\r\n";  //\r\n表示回车换行
               int t=0;
                t=Convert .ToInt16 (str );
                if(max<t )
                    max =t ;
            }
                sr.Close();
                fs.Close();
                richTextBox1.Text = mystr;
           textBox1 .Text  =max.ToString();

        }

        private void button2_Click(object sender, EventArgs e)
        {
             Random rdm = new Random();
            bool flag;
            for (int i = 0; i < 10; i++)
            {
                while (true)
                {
                    t = rdm.Next(0, 101);
                    flag = true;
                    for (int j = 0; j < i - 1; j++)
                        if (a[j] == t) flag = false;
                    if (flag == true) break;
                }
                a[i] = t;
            }
            int max = 0;
            for (int i = 1; i < 10; i++)
            {  
                richTextBox1.Text += a[i].ToString() + "\r\n";
               if (max < a[i])
                max =  a[i];
             }
             textBox1 .Text  = max.ToString();
        } //----- 标记1
        //-------------  这里 可能是 方法 或者 标记1出的 "}" 去掉  感觉是这个样子  没有 程序实现
        string pa = "aa.txt";
        FileStream fr = new FileStream("aa.txt", FileMode.Append);
        StreamWriter sr = new StreamWriter(fr, Encoding.Default);
        sr.WriteLine( richTextBox1.Text );//C#类、结构或接口成员声明中的标记“(”无效
        sr.Close();
        fs.Close();

        }
    }
2011-06-03 13:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-341605-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054050 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved