Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arr1 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- string FileName = "Evens.txt";
- DataSet<int, string> list = new DataSet<int, string>(arr1, FileName);
- list.WriteEven();
- list.WriteOdd();
- double[] arr2 = new double[] { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.1 };
- string FileName2 = "Odds.txt";
- DataSet<double, string> list2 = new DataSet<double, string>(arr2, FileName2);
- list2.WriteEven();
- list2.WriteOdd();
- }
- class DataSet<T, U>
- {
- T[] array;
- U FileName;
- public DataSet(T[] arr, U name)
- {
- array = arr;
- FileName = name;
- }
- T _value;
- public DataSet(T t)
- {
- this._value = t;
- }
- public void WriteEven()
- {
- FileStream outFile = new FileStream(FileName.ToString(), FileMode.Append, FileAccess.Write);
- using (StreamWriter file = new StreamWriter(outFile))
- for (int x = 0; x < array.Length; x++)
- {
- file.WriteLine(array[x]);
- x++;
- }
- }
- public void WriteOdd()
- {
- FileStream outFile = new FileStream(FileName.ToString(), FileMode.Append, FileAccess.Write);
- using (StreamWriter file = new StreamWriter(outFile))
- for (int x = 0; x < array.Length; x++)
- {
- x++;
- file.WriteLine(array[x]);
- }
- }
- }
- }
- }
- // Writer<int,string> list = new Writer<int, string>(arr, FileName);
- // forgot to make a generic class,not passing through
Add Comment
Please, Sign In to add comment