Operator '>' cannot be applied to operands of type 'Stad' and 'Stad'
using System;
using System.Collections.Generic;
using System.Linq;
class Stad
{
public string name { get; set; }
public int temp { get; set; }
public Stad(string name, int temp)
{
this.name = name;
this.temp = temp;
}
public string Name
{
get { return this.name; }
set { name = value; }
}
public int temperatur
{
get { return temp; }
set { temp = value; }
}
public override string ToString()
{
return name + " " + temp;
}
}
class program
{
static int Linsok(List<Stad> list, int key)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].temperatur == key)
return i;
}
return -1;
}
static void Bubblesort(List<Stad> temp)
{
int max = temp.Count - 1;
for (int i = 0; i < max; i++)
{
int nrLeft = max - i;
for (int j = 0; j < nrLeft; j++)
{
if (temp[j] > temp[j + 1]) !!!!! Denna rad är errorn på!!!!!!!
{
var tmp = temp[j];
var v = temp[j].temp > temp[j + 1].temp;
temp[j + 1] = tmp;
}
}
}
}
static void Main(string[] args)
{
List<Stad> myList = new List<Stad>();
bool avsluta = false;
while (!avsluta)
{
Console.Write("[A]ange temp i ny stad\n");
Console.Write("[B]Sök specifik temp\n");
Console.Write("[C]avsluta\n");
Console.Write("[D]sortera och skriv ut\n");
char menyVal;
menyVal = Console.ReadLine()[0];
switch (menyVal)
{
case 'a':
case 'A':
System.Console.Write("Stadens namn: ");
string name = Console.ReadLine();
System.Console.Write("Ange temperatur: ");
int temp = Convert.ToInt32(Console.ReadLine());
Stad stad = new Stad(name, temp);
if (temp >= 60 || temp <= -60)
Console.WriteLine("felaktig temp");
else
myList.Add(stad);
break;
case 'b':
case 'B':
Console.Write("Ange temperatur att söka: ");
string str = Console.ReadLine();
int key = Convert.ToInt32(str);
int index = Linsok(myList, key);
if (index == -1)
Console.WriteLine("stad med en temperaturen finns inte");
else
Console.WriteLine("temp: " + key + " finns i stad: " + myList[index].Name);
break;
case 'c':
case 'C':
Console.WriteLine("hejdå");
avsluta = true;
break;
case 'd':
case 'D':
Bubblesort(myList);
break;
default:
Console.WriteLine("Någonting gick fel. Hejdå");
avsluta = true;
break;
}
}
}
}
Förstår inte vad som är fel, blir galen