Write a portion of an array to text file in CSharp

Description

The following code shows how to write a portion of an array to text file.

Example


  //from  w  w w  .j a  va 2 s  .  co m

using System;
using System.IO;

public class MainClass
{
  static void Main(string[] args)
  {
    StreamWriter MyStreamWriter = new StreamWriter(@"c:\Testing.txt");

    char[] MyCharArray = new char[100];

    for (int i = 0; i < 99; i++)
    {
      MyCharArray[i] = (char)i;
    }

    MyStreamWriter.Write(MyCharArray, 25, 30);


    MyStreamWriter.Close();
  }
}




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip