fork download
  1. using static System.Console;
  2. using System.IO;
  3.  
  4. namespace ConsoleApplication1 {
  5. public class Program {
  6. public static void Main(string[] args) {
  7. string[] names = new string[6];
  8. WriteLine("Escolha:\n1 - adicionar\n2 - Visualizar\n 3 - Sair");
  9. var valor = 0;
  10. if (!int.TryParse(ReadLine(), out valor)) WriteLine("Opção inválida");
  11. if (valor == 1) {
  12. WriteLine("Escreva o nome do autor/grupo, nome do CD, ano de edição, nome da editora, total de tempo e número de faixas: ");
  13. for (int i = 0; i < 6; i++) names[i] = ReadLine();
  14. using (var sw = new StreamWriter(@"C:\Users\gabri\Desktop\trabalho.txt")) {
  15. for (int i = 0; i < 6; i++) sw.WriteLine(names[i]);
  16. }
  17. }
  18. if (valor == 2) {
  19. WriteLine("FICHEIRO .txt: \n");
  20. using (var reader = File.OpenText(@"C:\Users\gabri\Desktop\trabalho.txt")) {
  21. string line;
  22. while ((line = reader.ReadLine()) != null) WriteLine(line);
  23. }
  24. ReadKey();
  25. }
  26. if (valor == 3) WriteLine("Adeus");
  27. }
  28. }
  29. }
  30.  
  31. //https://pt.stackoverflow.com/q/158859/101
Success #stdin #stdout 0.02s 16116KB
stdin
Standard input is empty
stdout
Escolha:
1 - adicionar
2 - Visualizar
 3 - Sair
Opção inválida