Доработать операторы сравнения - C#
Формулировка задачи:
namespace BuilderScripts
{
public partial class Form1
{
private static int nextId = 0;
public struct Link
{
public readonly SOutput Output;
public readonly SInput Input;
public Link(SOutput Output, SInput Input)
{
this.Input = Input;
this.Output = Output;
}
}
public struct SInput
{
private readonly int ID;
public readonly string name;
public SInput(string name)
{
ID = nextId;
this.name = name;
nextId++;
}
public override int GetHashCode()
{
int hash = 0;
for (int i = 0; i < name.Length; i++) hash += name[i];
return hash << ID;
}
public static bool operator ==(SInput c1, SInput c2)
{
if (c1.ID == c2.ID && c1.name == c2.name)
return true;
return false;
}
public static bool operator !=(SInput c1, SInput c2)
{
if (c1.name != c2.name)
return true;
return false;
}
}
public struct SOutput
{
private readonly int ID;
public readonly string name;
public SOutput(string name)
{
ID = nextId;
this.name = name;
nextId++;
}
public override int GetHashCode()
{
int hash = ID * name.Length;
for (int i = 0; i < name.Length; i++) hash += name[i];
return hash;
}
public static bool operator ==(SOutput c1, SOutput c2)
{
if (c1.ID == c2.ID && c1.name == c2.name)
return true;
return false;
}
public static bool operator !=(SOutput c1, SOutput c2)
{
if (c1.name != c2.name)
return true;
return false;
}
}
}
}Решение задачи: «Доработать операторы сравнения»
textual
Листинг программы
public static bool operator ==(SInput c1, SInput c2)
{
if (c1.ID == c2.ID && c1.name == c2.name)
return true;
return false;
}
public static bool operator !=(SInput c1, SInput c2)
{
return !(c1 == c2);
}