question

joshBAUER-1782 avatar image
0 Votes"
joshBAUER-1782 asked ·

c# swap operator

 class ww
 {
     static public bool operator <==>(ww firstParam,ww secondParam ){
         return false;
     }
 }

I do like above swaping operator. In c++ it would work fine because swaping operators
were introduced in c++ version15.

By swaping I mean to exchange two values.

How to do <=> operator in c#?

If it is not yet possible, would Microsoft make it possible same like they did it for c++?

dotnet-csharp
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered ·

Language feature requests should be posted to the Github repo for the compiler. In general you are required to fill out a lengthy form on the proposal of how it should work, rationale, etc.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered ·

Could you show a reference (documentation) for swapping operators in C++?

There is also a new “<=>” operator in C++, but it does not perform swapping. The equivalent in C# is the IComparable interface, I think.

· 2 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Though <=> operator can be programmed to perform swaping operation.

Would Microsoft also introduce <=> in C#?

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 joshBAUER-1782 ·

I am not sure about both.

There is already a new way of swapping in modern C#:

(a, b) = (b, a); // swap a and b


0 Votes 0 ·