witam
Otóż mam problem z programem mianowicie chcę żeby podzielił zdanie na wyrazy i gdy po podzieleniu będę chciał ustawić wyraz na "bo" to ma wyskakiwać błąd ale właśnie nie wiem dlaczego mi nie wychodzi.
namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args)
{
Zdanie zdanie = new Zdanie("To jest zdanie");
zdanie[0] = "bo";
Console.WriteLine(zdanie[0]);
Console.ReadLine();
}
}
}
class Zdanie
{
string[] slowa;
public Zdanie(string zdanie)
{
List<string> lista = new List<string>();
this.slowa = zdanie.Split();
foreach (string element in slowa)
{
Console.WriteLine(element);
}
}
public string this[int n]
{
get
{
return slowa[n];
}
set
{
if (slowa[n] == "bo")
{
Console.WriteLine("Wprowadziles bo\nNacisnij klawisz aby wyjsc");
Environment.Exit(0);
}
else
{
slowa[n] = value;
}
}
}
}