Advertisement
Guest User

C# Error

a guest
Jun 14th, 2016
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. using System.IO;
  2. using System;
  3. using System.Linq;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6.  
  7. public struct Player
  8. {
  9.     public string Name;
  10.     public string Nickname;
  11. }
  12.  
  13. public class Application
  14. {
  15.     static void Main()
  16.     {
  17.         int i = 0;
  18.         Console.WriteLine("Enter number of players:");
  19.         int num_players = Convert.ToInt32(Console.ReadLine());
  20.         Player[] players = new Player[num_players];
  21.         for(i = 0; i < num_players; i++)
  22.         {
  23.             Console.WriteLine("Player Name:");
  24.             players[i].Name = Console.ReadLine();
  25.             Console.WriteLine("Player Nickname:");
  26.             players[i].Nickname = Console.ReadLine();
  27.         }
  28.         foreach(Player x in players)
  29.         {
  30.             Console.WriteLine("Player Name: " + x.Name);
  31.             Console.WriteLine("Player Nickname: " + x.Nickname);
  32.         }
  33.         Console.WriteLine("Quantos Players?");
  34.         num_players = Convert.ToInt32(Console.ReadLine());
  35.         Array.Resize(ref players, num_players);
  36.         for(int k = 0; k == num_players; k--)
  37.         {
  38.             players[k] = players[k + 1];
  39.         }
  40.         for(; i < num_players; i++)
  41.         {
  42.             Console.WriteLine("Player Name:");
  43.             players[i].Name = Console.ReadLine();
  44.             Console.WriteLine("Player Nickname:");
  45.             players[i].Nickname = Console.ReadLine();
  46.         }
  47.         foreach(Player x in players)
  48.         {
  49.             Console.WriteLine("Player Name: " + x.Name);
  50.             Console.WriteLine("Player Nickname: " + x.Nickname);
  51.         }
  52.         string file_directory = @"Cache.txt";
  53.         using (StreamWriter sw = File.CreateText(file_directory))
  54.         {
  55.             for(int k = 0; k < num_players; k++)
  56.             {
  57.                 sw.WriteLine(players[k].Name);
  58.                 sw.WriteLine(players[k].Nickname);
  59.             }
  60.         }
  61.         using (StreamReader sr = File.OpenText(file_directory))
  62.         {
  63.             string s = "";
  64.             do{
  65.                 s = sr.ReadLine();
  66.                 if(s == null)
  67.                 {
  68.                     num_players = num_players + 1;
  69.                     Array.Resize(ref players, num_players);
  70.                     players[num_players].Name = s;
  71.                 }
  72.                 s = sr.ReadLine();
  73.                 if(s == null)
  74.                 {
  75.                     players[num_players].Nickname = s;
  76.                 }
  77.             } while (s != null);
  78.         }
  79.         foreach(Player x in players)
  80.         {
  81.             Console.WriteLine(x.Name);
  82.             Console.WriteLine(x.Nickname);
  83.         }
  84.         Console.ReadKey();
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement