Witam tak jak w temacie nie mogę zastosować znaku && w metodzie UsunOcene zdefiniowanej w klasie Student. Dodam, że pozostałe klasy są dobrze napisane, dlatego nie wrzuciłem całego kodu. (Oczywiście mogę je dorzucić jeśli jednak ktoś chce zerknąć na nie)
Błąd kompilacji:
Error 1 Operator '&&' cannot be applied to operands of type 'bool' and 'string'
Error 2 Operator '&&' cannot be applied to operands of type 'string' and 'bool'
Bardzo proszę o pomoc ;)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Osoba o = new Osoba("Adam", "Miś", "20.03.1980");
Osoba o2 = new Student("Michał", "Kot", "13.04.1990", 2, 1, 12345);
Osoba o3 = new Pilkarz("Mateusz", "Żbik", "10.08.1986", "obrońca", "FC Czestochowa");
o.WypiszInfo();
o2.WypiszInfo();
o3.WypiszInfo();
Student s = new Student("Krzysztof", "Jeż", "22.12.1990", 2, 5, 54321);
Pilkarz p = new Pilkarz("Piotr", "Kos", "14.09.1984", "napastnik", "FC Politechnika");
s.WypiszInfo();
p.WypiszInfo();
((Pilkarz)o3).StrzelGola();
p.StrzelGola();
p.StrzelGola();
o3.WypiszInfo();
p.WypiszInfo();
Console.ReadKey();
((Student)o2).DodajOcene("PO", "20.02.2011", 5.0);
((Student)o2).DodajOcene("Bazy danych", "13.02.2011", 4.0);
o2.WypiszInfo();
s.DodajOcene("Bazy danych", "01.05.2011", 5.0);
s.DodajOcene("AWWW", "11.05.2011", 5.0);
s.DodajOcene("AWWW", "02.04.2011", 4.5);
s.WypiszInfo();
s.UsunOcene("AWWW", "02.04.2011", 4.5);
s.WypiszInfo();
s.DodajOcene("AWWW", "02.04.2011", 4.5);
// s.UsunOceny("AWWW");
s.WypiszInfo();
s.DodajOcene("AWWW", "02.04.2011", 4.5);
// s.UsunOceny();
s.WypiszInfo();
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Student : Osoba
{
public int rok { set; get; }
public int grupa { set; get; }
public int nrIndeksu { set; get; }
private List<Ocena> oceny = new List<Ocena>();
public Student(string imie_, string nazwisko_, string dataUrodzenia_, int rok_, int grupa_, int nrIndeksu_)
: base(imie_, nazwisko_, dataUrodzenia_)
{
rok = rok_;
grupa = grupa_;
nrIndeksu = nrIndeksu_;
}
public override void WypiszInfo()
{
base.WypiszInfo();
Console.WriteLine(rok + " " + grupa + " " + nrIndeksu + " ");
}
public void DodajOcene(string nazwaPrzedmiotu, string data, double wartosc)
{
oceny.Add(new Ocena(nazwaPrzedmiotu,data,wartosc));
}
public void WypiszOceny()
{
for (int i = 0; i < oceny.Count; i++)
{
Console.WriteLine(oceny[i]);
}
}
public void UsunOcene(string a1,string a2,double a3)
{
for (int i = 0; i < oceny.Count; )
{
Ocena o = oceny[i];
if (o.nazwaPrzedmiotu == a1 && o.data = a2 && o.wartosc == a3)
{
oceny.RemoveAt(i);
}
else
{
++i;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Student : Osoba
{
public int rok { set; get; }
public int grupa { set; get; }
public int nrIndeksu { set; get; }
private List<Ocena> oceny = new List<Ocena>();
public Student(string imie_, string nazwisko_, string dataUrodzenia_, int rok_, int grupa_, int nrIndeksu_)
: base(imie_, nazwisko_, dataUrodzenia_)
{
rok = rok_;
grupa = grupa_;
nrIndeksu = nrIndeksu_;
}
public override void WypiszInfo()
{
base.WypiszInfo();
Console.WriteLine(rok + " " + grupa + " " + nrIndeksu + " ");
}
public void DodajOcene(string nazwaPrzedmiotu, string data, double wartosc)
{
oceny.Add(new Ocena(nazwaPrzedmiotu,data,wartosc));
}
public void WypiszOceny()
{
for (int i = 0; i < oceny.Count; i++)
{
Console.WriteLine(oceny[i]);
}
}
public void UsunOcene(string a1,string a2,double a3)
{
for (int i = 0; i < oceny.Count; )
{
Ocena o = oceny[i];
if (o.nazwaPrzedmiotu == a1 && o.data = a2 && o.wartosc == a3)
{
oceny.RemoveAt(i);
}
else
{
++i;
}
}
}
}
}