Three wine glasses

How to swap two numbers in C#

In this article, we will discuss how to swap two numbers in C#.

  • we can swap two numeric values with temporary variable
  • we can also use XOR(^) operator
  • we can swap two numeric values with simple arithmetics

With temporary variable:

var temp = first;
first = second;
second = temp;

With XOR

first = first ^ second;
second = second ^ first;
first = first ^ second;

And as following

first = first + second;
second = first - second;
first = first - second;

You can find the code at my GitHub

SoftUni-Tech-Fest-with-winner-Imanuella-Busari

SoftUni Tech Fest

I took part as a mentor at SiftUni Tech Fest which was held on 4-5 June 2016.

SoftUni Tech Fest is hackathon that brings together students, professionals and technology enthusiasts from across the country to seek out and develop technological solutions to problems of the modern world. The theme was Technology in Education. The category that I was mentoring was Web Based Applications (under 18y.o.). It was very nice to see so many young people wanting to learn and code.

On the picture you can see me with the winner Immanuella Busari (in the previously mentioned category). A young and inspirational girl. Wish her all the best.