want this code in C# ,

void sort(int *a, int size)
   int i,j, swapped=0;
   for (j=size-1; j>0; j--) {
     for (i=0; i<j; i++) {
       if (a[i+1] < a[i]) {
          swap(a[i], a[i+1]); swapped=1
     if ( swapped == 0 ) break;

Procedure signature void sort(int *a, int size) without any pointers is void sort(int[] a, int size) You can do the rest by yourself by copy/pasting the code to the editor which will tell you about syntax errors.

Procedure void swap(int a, int b) simply swaps the values of a and b. That's easy to write.

Bubble-sort algorithm works fine with a few items in an array. If you have large arrays (+100 items) consider using quick-sort algorithm instead.

.NET has also built-in Array.Sort() method which I would use myself.

In the rules, it says you must have at least attempted it yourself.
Nevertheless, you should add one to the swaps- it may be useful later.
You will need to make a swap event.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.