I have structure like this below. Now, I want swap 2 structures.
public struct Pair<T, U>
{
public readonly T Fst;
public readonly U Snd;
public Pair(T fst, U snd)
{
Fst = fst;
Snd = snd;
}
public override string ToString()
{
return "(" + Fst + ", " + Snd + ")";
}
**public Pair<U, T> Swap(out Pair<U, T> p1, Pair<T,U> p2)
{
p1 = new Pair<U, T>(p2.Snd, p2.Fst);
return p1;
}**
}
In Main method try this:
Pair<int, String> t1 = new Pair<int, string>();
Pair<String, int> t2 = new Pair<string,int>("Anders",13);
**t1.Swap(out t1,);** //compilator tells -> https://i.stack.imgur.com/dM6P0.png
Parameters on Swap method are different than compilator achive.
There is no need for out parameters here. Just define it as:
You can then do: