Witam mam kilka pytań:
- Jak zrobić aby do listy można było dodawać nowe osoby do listy przez użytkownika? Próbowałem na różne sposoby ale nie działało.
- Jak wczytać znak z konsoli? Chodzi mi o to, żę jak nacisnę ESC czyli 27 to mi zakończy, a jak co innego to będzie kontynuować pętle.
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
var Dane2 = new List<Lista>();
foreach (var Lista1 in Dane2)
{
if (Dane2 == null) //tu chciałem, że jak lista jest pusta to wypisuje komunikat "pusto", ale nie działa
WriteLine("Pusto");
else
{
WriteLine(Formatowanie.Format(Lista1));
}
}
WriteLine("Dodac nowego obywatela?");
ReadKey();
}
}
}
------------klasa1-----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication12
{
class Formatowanie
{
public static string Format(Lista dane)
{
return dane.Imie;
}
}
}
---------------klasa2------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication12
{
public class Lista
{
public string Imie { get; set; }
public Lista(string imie)
{
Imie = imie;
}
}
}