Thursday 27 May 2021

Basic Generic class and method

 public class TestList<T>

{

    public void Add(T input) { }

}

class TestGList

{

    private class Example1 { }

    static void Main()

    {

        // Declare a list of type int.

        TestList<int> list1 = new TestList<int>();

        list1.Add(1);


        // Declare a list of type string.

        TestList<string> list2 = new TestList<string>();

        list2.Add("");


        // Declare a list of type Example1.

        TestList<Example1> list3 = new TestList<Example1>();

        list3.Add(new Example1());

    }

}

Generic Method in C#

 public class GClass {

      static void Swap2Values<T>(T lhs, T rhs) {

         T temp;     temp = lhs;    lhs = rhs;    rhs = temp;

      }

      static void Main(string[] args) {

         int a, b;   char c, d;   a = 5;  b = 10;  c = 'h';  d = 'k';

         // Before swap display values :

         Console.WriteLine("Before Swap:");

         Console.WriteLine("a = {0}, b = {1}", a, b);

         Console.WriteLine("-------:");

         Console.WriteLine("c = {0}, d = {1}", c, d);

         //call generic Method

         Swap<int>(a, b);

         Swap<char>(c,  d);

         //After swap:

         Console.WriteLine("After swap:");

         Console.WriteLine("a = {0}, b = {1}", a, b);

         Console.WriteLine("--------");

         Console.WriteLine("c = {0}, d = {1}", c, d);

}

}

Tuesday 18 May 2021

How to create the storage account in azure

 az storage account create \

  --kind StorageV2 \

  --resource-group r-g-name-test321 \

  --location centralus \

  --name satest1