Guest User

Untitled

a guest
Jan 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] arr1 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  14. string FileName = "Evens.txt";
  15. DataSet<int, string> list = new DataSet<int, string>(arr1, FileName);
  16. list.WriteEven();
  17. list.WriteOdd();
  18. double[] arr2 = new double[] { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.1 };
  19. string FileName2 = "Odds.txt";
  20. DataSet<double, string> list2 = new DataSet<double, string>(arr2, FileName2);
  21. list2.WriteEven();
  22. list2.WriteOdd();
  23. }
  24. class DataSet<T, U>
  25. {
  26. T[] array;
  27. U FileName;
  28. public DataSet(T[] arr, U name)
  29. {
  30. array = arr;
  31. FileName = name;
  32. }
  33. T _value;
  34. public DataSet(T t)
  35. {
  36. this._value = t;
  37. }
  38.  
  39. public void WriteEven()
  40. {
  41. FileStream outFile = new FileStream(FileName.ToString(), FileMode.Append, FileAccess.Write);
  42. using (StreamWriter file = new StreamWriter(outFile))
  43. for (int x = 0; x < array.Length; x++)
  44. {
  45. file.WriteLine(array[x]);
  46. x++;
  47. }
  48. }
  49.  
  50. public void WriteOdd()
  51. {
  52. FileStream outFile = new FileStream(FileName.ToString(), FileMode.Append, FileAccess.Write);
  53. using (StreamWriter file = new StreamWriter(outFile))
  54. for (int x = 0; x < array.Length; x++)
  55. {
  56. x++;
  57. file.WriteLine(array[x]);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. // Writer<int,string> list = new Writer<int, string>(arr, FileName);
  64. // forgot to make a generic class,not passing through
Add Comment
Please, Sign In to add comment