Wednesday, July 10, 2013
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ThousandNumbersIO
{
class Program
{
static void Main(string[] args)
{
printnumbers(10);
readnumbers();
Console.ReadKey();
}
static void printnumbers(int num1)
{
Random rnd = new Random();
int int1;
string[] lines = { "First line", "Second line", "Third line" };
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Public\TestFolder\WriteLines.txt", true))
for (int ii = 0; ii < num1; ii++)
{
int1 = rnd.Next(1, 10);
file.WriteLine(Convert.ToString(int1));
}
}
static void readnumbers()
{
// The files used in this example are created in the topic
// How to: Write to a Text File. You can change the path and
// file name to substitute text files of your own.
// Example #1
// Read the file as one string.
string text = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\WriteLines.txt");
// Display the file contents to the console. Variable text is a string.
System.Console.WriteLine("Contents of WriteText.txt = {0}", text);
// Example #2
// Read each line of the file into a string array. Each element
// of the array is one line of the file.
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\WriteLines.txt");
// Display the file contents by using a foreach loop.
System.Console.WriteLine("Contents of WriteLines2.txt = ");
foreach (string line in lines)
{
// Use a tab to indent each line of the file.
Console.WriteLine("\t" + line);
}
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
}
Posted on 7:29 AM by Erdem
Subscribe to:
Post Comments (Atom)
Categories
Blog Archive
-
▼
2013
(24)
-
▼
July
(14)
- Polymorphism nedir
- Static Fields in a class
- What is a constructor
- Defining and using a class and Constructor
- Memory Usage by Classes, Methods and Functions
- Encapsulation 3
- What is Encapsulation 2
- What is Encapsulation
- Reading and Writing to a File
- Exception Example
- Beginning Visual C# 2010
- Animated Elipse in C#
- Ref and Out in Visual C#
- How to download an image from a website using c#
-
▼
July
(14)
Popular Posts
Powered by Blogger.
0 comments:
Post a Comment