String Array to a text file

All C# objects, variables, and constants must have a specific type. An array is a data structure that contains multiple variables of the same type. Arrays helps us create shorter and simpler code in many situations.

C# arrays are zero indexed, that is the array indexes start at zero. The default number of array elements is set to zero and the reference element is set to null.

The elements of an array can be of any type, including an array type. The following C# source code shows how to write the array content into a text file.

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
	public partial class Form1 : Form
		public Form1()

		private void button1_Click(object sender, EventArgs e)
			string[] months = new string[12];
			months[0] = "Jan";
			months[1] = "Feb";
			months[2] = "Mar";
			months[3] = "Apr";
			months[4] = "May";
			months[5] = "Jun";
			months[6] = "Jul";
			months[7] = "Aug";
			months[8] = "Sep";
			months[9] = "Oct";
			months[10] = "Nov";
			months[11] = "Dec";
			System.IO.File.WriteAllLines("c:\\file.txt", months);
} (C) 2019    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About