1~1000这些数字
生成-
----------------------------
0001
0002
0003
0004
.
.
.
.
0230
0231
.
.
.
.
.
1000
------------------------------
这种格式的

解决方案 »

  1.   


    class Program
    {
        static void Main(string[] args)
        {
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter("test.txt"))
            {
                for (int i = 1; i <= 1000; i++)
                {
                    sw.WriteLine(i.ToString("0000"));
                }
            }
        }
    }
      

  2.   

    生成没问题啊.        private void WriteIntToText()
            {
                using (StreamWriter sw = File.CreateText(@"C:\a.txt"))
                {
                    for (int i = 1; i <= 1000; i++)
                        sw.WriteLine(i.ToString("0000"));
                    sw.Close();
                }
            }
      

  3.   

    一楼正解,二楼sw.Close();画蛇添足
      

  4.   


    为什么到我这里报错啊??
    我的人品问题???
    --------------------------using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace _32423
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                if (!File.Exists(@"c:\abc.txt")) 
                    File.Create("c:\\abc.txt"); 
                StreamWriter writer = new StreamWriter(@"D:\abc.txt"); 
                for(int i=0;i <=100;i++) 
                { 
                    string w=""; 
                    w=i.ToString()+'\r'+'\n'; 
                    writer.Write(w); 
                } 
                writer.Close(); 
            }
        }
    }
      

  5.   

    你在C盘建了个abc,却写到d盘去了.
      

  6.   

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms; 
    using System.IO;namespace _32423 

        public partial class Form1 : Form 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
            }         private void button1_Click(object sender, EventArgs e) 
            { 
                if (!File.Exists(@"c:\abc.txt")) 
                    File.Create(@"c:\abc.txt"); 
                StreamWriter writer = new StreamWriter(@"c:\abc.txt"); 
                for(int i=0;i <=100;i++) 
                { 
                    writer.WriteLine(i.ToString("0000")); 
                } 
                writer.Close(); 
            } 
        } 
    }
      

  7.   

    不是那的问题,
    报错错误 1 当前上下文中不存在名称“File” C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\432423\432423\Form1.cs 20 18 432423
    错误 2 当前上下文中不存在名称“File” C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\432423\432423\Form1.cs 21 17 432423
    错误 3 找不到类型或命名空间名称“StreamWriter”(是否缺少 using 指令或程序集引用?) C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\432423\432423\Form1.cs 22 13 432423
    错误 4 找不到类型或命名空间名称“StreamWriter”(是否缺少 using 指令或程序集引用?) C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\432423\432423\Form1.cs 22 39 432423
      

  8.   

    using System.IO; 
      

  9.   

    在程序的顶部 using 部分加入
    using System.IO;
      

  10.   

    有这句就不是你那样了 writer.WriteLine(i.ToString("0000")); 
    就会是
    0001
    0002
    0003
    0004




    0230
    0231





      

  11.   

    错误 1 当前上下文中不存在名称“i” C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\fgfdgdgf\fgfdgdgf\Form1.cs 24 31 fgfdgdgf
      

  12.   


    你你你,新新手.先从基础学起吧.
    我7楼的代码你先copy过去用用.
      

  13.   

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms; 
    using System.IO; namespace _32423 

        public partial class Form1 : Form 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
            }         private void button1_Click(object sender, EventArgs e) 
            { 
                if (!File.Exists(@"c:\abc.txt")) 
                    File.Create(@"c:\abc.txt"); 
                StreamWriter writer = new StreamWriter(@"c:\abc.txt"); 
                for(int i=0;i <=100;i++) 
                { 
                    writer.WriteLine(i.ToString("0000")); 
                } 
                writer.Close(); 
            } 
        } 
    }