-2

I did some Sorting program in C#. and i want to use this keyword in sorce.

here is my source.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsDc
{
    public class jisik
    {
        public static void Main()
        {
            int[] array = new int[5];
            for (int i = 0; i < 5; i++)
            {
                Console.Write((i + 1) + "input number : ");
                array[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(array);
            Console.Write("decending  :");
            foreach (int i in array)
                Console.Write(i);
            Console.WriteLine();
            Console.Write("ascending  :");
            Array.Reverse(array);
            foreach (int i in array)
                Console.Write(i);
            Console.WriteLine();
        }
    }
}

.....and i want to use this keyword like this source.

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;

  namespace ConsoleApplication3
  {
      class Myclass
      {
          int a, b;

          public Myclass()
          {
             this.a = 5425;
             Console.WriteLine("Myclass()");
          }

          public Myclass(int b) : this()  
          {
             this.b = b;
             Console.WriteLine("Myclass({0})", a);
          }

          public void PrintFields()
          {
             Console.WriteLine("a : {0}, b : {1}", a,b);
          }
      }
      class MainApp
      {
          static void Main(string[] args)
          {
             Myclass a = new Myclass();
             a.PrintFields();
             Console.WriteLine();

             Myclass b = new Myclass(1);
             b.PrintFields();
             Console.WriteLine();
          }
      }
  }

I dont know how to use this in sorting. please, teach me.

Venson
  • 1,772
  • 17
  • 37
KyHa
  • 7
  • 2

1 Answers1

0

You can't use this in static method. Please try to learn basics of OOP.

Imran Sh
  • 1,623
  • 4
  • 27
  • 50