HI, I’M SAMEER BAHAD

We are next Full Stack Developer

My Services

WHAT I CAN DO
We are providing complex software concept into simplified concept with real world example. Software engineering coming from daily and neighbor things. We are start with questions, connect to real example and produce concept on it. We discuss most on problem solving with programming concept.
  • C#, ASP.net, WPF, API 90%
  • Angular, Java Script, HTML5, CSS 70%
  • Mysql, SQL, SQL Light, Cloud 86%
  • Blogger 60%
  • Jira, Git, Cloud 80%

My Blog

MY BEST WORKS
no image
What is Clone ?
It look like duplicate of original
Reference is same for string
And different for objects
Once clone create it acts as independent 


class SiteName : Icloneable
    {

        private string SiteDomain { get; }
        private string Protocal { get; }

        public SiteName(SiteName siteName)
        {
            this.Protocal = siteName.Protocal;
            this.SiteDomain = siteName.SiteDomain;
        }

        public SiteName(string SiteName)
        {
            SiteDomain = SiteName.Split('.')[2];
            Protocal = SiteName.Split('/').FirstOrDefault();
        }

        public string showData
        {
            get { return $"Domain={SiteDomain} Protocal={Protocal}"; }
        }
           
        public object Clone()
        {
//Runtime exception : System.StackOverflowException  HResult=0x800703E9
//  Message=Exception of type 'System.StackOverflowException' was thrown.
            //return Clone();

// This will run as expected
            //return this.MemberwiseClone();

//Runtime exception : System.InvalidCastException
//Message=Unable to cast object of type 'System.String' to type 'Clone_Concept.SiteName'.
            //return showData;

            //return this.Clone();
            return MemberwiseClone();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //string clone
            string Site1Name = "http://www.abc.com";
            Console.WriteLine(Site1Name);
           
            string Site2Name = (string)Site1Name.Clone();
            Console.WriteLine(
                $"Reference {object.ReferenceEquals(Site1Name, Site2Name)}" +
                $"\n Is Equal {object.Equals(Site1Name,Site2Name)}");
            Console.WriteLine();
           
            //Object Clone
            SiteName siteNameObj1 = new SiteName(Site1Name);
            Console.WriteLine(siteNameObj1.showData);
           
            SiteName siteNameObj2 = (SiteName)siteNameObj1.Clone();
            Console.WriteLine(
                $"Reference {object.ReferenceEquals(siteNameObj1, siteNameObj2)}" +
                $"\n Is Equal {object.Equals(siteNameObj1, siteNameObj2)}");

            Console.Read();
        }
    }

no image



class Coffee
    {
        private string BoilWater;
        private string CoffeePowder;       
        private string Sugar;
        public bool IsCoffeeReady = false;
        public Coffee(string boilWater, string coffeePowder, string sugar)
        {
            Console.WriteLine("Start Coffee making");
            BoilWater = boilWater;
            Console.WriteLine("Start boiling water");
            Thread.Sleep(1000);
            Console.WriteLine("water boiled add coffee");
            CoffeePowder = coffeePowder;
            Console.WriteLine("Ster and boild");
            Thread.Sleep(500);
            Console.WriteLine("Add sugar");
            Sugar = sugar;
            Console.WriteLine("coffee ready");
            IsCoffeeReady = true;
        }
        public void PourCoffee()
        {
            if(IsCoffeeReady)
                Console.WriteLine("Coffee Ready for pour");
        }
    }

    class Egg
    {
        private string boilWater;

        public Egg(int eggcount)
        {
            //add egg into water and start boiling water
            Console.WriteLine($"put {eggcount} egg into the water");
            Console.WriteLine("water is boiling now");
            Thread.Sleep(1500);
            Console.WriteLine("egg are boiled");
            Console.WriteLine("pealing the egg");
            Thread.Sleep(1000);
            Console.WriteLine("Egg is ready");
        }
    }

    class Toast
    {
        private int Breadcount;
        public Toast(int breadcount)
        {
            Breadcount = breadcount;
            Console.WriteLine($"Put {Breadcount} bread slice into toster");
            Console.WriteLine("Tostes are making");
            Thread.Sleep(1500);
            Console.WriteLine("Toste are ready ");
        }

        public void ApplyButter(Toast tos)
        {
            Console.WriteLine($"Appling butter on {tos.Breadcount} tostes");
            Thread.Sleep(1000);
            Console.WriteLine($"{tos.Breadcount} tostes are ready with butter");
        }

        public void ApplyJam(Toast tos)
        {
            Console.WriteLine($"Appling Jam on {tos.Breadcount} toastes");
            Thread.Sleep(1000);
            Console.WriteLine($"{tos.Breadcount} tostes are ready with jam");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Coffee cup =new Coffee("Water", "Coffee", "Sugar");
            Console.WriteLine("coffee is ready");
            Egg eggs = new Egg(2);
            Console.WriteLine("eggs are ready");
         
            Toast toast = new Toast(2);
            toast.ApplyButter(toast);
            toast.ApplyJam(toast);
            Console.WriteLine("toast is ready");
           
            Console.WriteLine("Breakfast is ready!");
            Console.Read();
        }
    }


public class Coffee
    {
        public bool IsCoffeeReady = false;
        public Coffee(int cups)
        {
            Console.WriteLine("Coffee :Start Coffee making");

            Console.WriteLine("Coffee :Start boiling water for coffee......");
            Thread.Sleep(10000);
            Console.WriteLine("Coffee :water boiled add coffee powder ");

            Console.WriteLine("Coffee :Ster and boil");
            Thread.Sleep(500);
            Console.WriteLine("Coffee :Add sugar");
            Thread.Sleep(500);
            Console.WriteLine($"Coffee :{cups} cups coffee ready");
            IsCoffeeReady = true;
        }
        public void PourCoffee()
        {
            Console.WriteLine("Coffee : Coffee Ready for pour");
        }
    }

    class Egg
    {
        public Egg(int eggcount)
        {
            Console.WriteLine($"Egg: put {eggcount} egg into the water");
            Console.WriteLine("Egg: water is boiling .....");
            Thread.Sleep(1500);
            Console.WriteLine("Egg: egg are boiled");
            Console.WriteLine("Egg: pealing the egg");
            Thread.Sleep(1000);
            Console.WriteLine("Egg: Egg is ready");
        }
    }

    class Toast
    {
        private int Breadcount;
        public Toast(int breadcount)
        {
            Breadcount = breadcount;
            Console.WriteLine($"Toast : Put {Breadcount} bread slice into toaster");
            Console.WriteLine("Toast : bread are processing .....");
            Thread.Sleep(15000);
            Console.WriteLine("Toast :Toste are ready ");
        }

        public void ApplyButter(Toast tos)
        {
            Console.WriteLine($"Butter On Toast :Appling butter on {tos.Breadcount} tostes.....");
            Thread.Sleep(12000);
            Console.WriteLine($"Butter On Toast :{tos.Breadcount} tostes are ready with butter");
        }

        public void ApplyJam(Toast tos)
        {
            Console.WriteLine($"Jam on Toast : Appling Jam on {tos.Breadcount} toastes......");
            Thread.Sleep(100);
            Console.WriteLine($"Jam on Toast : {tos.Breadcount} tostes are ready with jam");
        }
    }

   

    class Program
    {
        public static int MakeCoffee()
        {
            int cup = 2;
            Coffee coffee = new Coffee(cup);
            coffee.PourCoffee();
            return cup;
        }

        public static int MakeEggs()
        {
            int numberofeggs = 2;
            Egg egg = new Egg(numberofeggs);
            return numberofeggs;
        }

        public static int MakeToast()
        {
            int breadcount = 2;
            Toast toast = new Toast(breadcount);
            toast.ApplyButter(toast);
            toast.ApplyJam(toast);
            return breadcount;
        }
        //static async Task<Toast> MakeToastAsync()
        //{
        //    int breadcount = 2;
        //    Toast toast = new Toast(breadcount);           
        //    toast.ApplyButter(toast);
        //    toast.ApplyJam(toast);           
        //    return toast;
        //}
        public static async void CallTaskmethods()
        {
            Console.WriteLine("## Group Task Asynchonously ##");

            Task<int> coffeeTask = new Task<int>(MakeCoffee);
            coffeeTask.Start();
            //Console.WriteLine("Start coffee making");
            //int counts = await coffeeTask;
            //Console.WriteLine("Coffee task completed");
            //Console.WriteLine();

            Task<int> eggTask = new Task<int>(MakeEggs);
            eggTask.Start();
            //Console.WriteLine("Egg task Start");
            //counts = await eggTask;
            //Console.WriteLine("Egg task completed");
            //Console.WriteLine();

            Task<int> toastTask = new Task<int>(MakeToast);
            toastTask.Start();
            //var toastTask = MakeToastAsync();
            Console.WriteLine();

            var alltask = new List<Task> { coffeeTask, eggTask, toastTask };
            while (alltask.Any())
            {
                Task finished = await Task.WhenAny(alltask);
                if (finished == coffeeTask)
                {
                    Console.WriteLine("#### Coffee Task Completed");
                    alltask.Remove(coffeeTask);
                    var coffe = await coffeeTask;
                }
                else if (finished == eggTask)
                {
                    Console.WriteLine("#### Egg Task Completed");
                    alltask.Remove(eggTask);
                    var eggs = await eggTask;                   
                }
                else if (finished == toastTask)
                {
                    Console.WriteLine("#### Toast Task Completed");
                    alltask.Remove(toastTask);
                    var toasts = await toastTask;
                }
                else
                    alltask.Remove(finished);
            }
            Console.WriteLine("####Break-Fast is ready ");
        }

        static void Main(string[] args)
        {
            CallTaskmethods();
            Console.Read();
        }
    }

no image

Copy work as copying object not reference
When we need only value to use
We can use Copy
Same for Copy constructor
We need to copy constructor and paste into the other one without reference.

class Program
    {
        static void Main(string[] args)
        {
            string ABC_SiteUrl = "www.abc.com";
            string XYZ_SiteUrl = "www.xyz.com";
            Console.WriteLine($"Original Values 1={ABC_SiteUrl} 2={XYZ_SiteUrl}");
            Console.WriteLine(
                $"Reference  {object.ReferenceEquals(ABC_SiteUrl,XYZ_SiteUrl)}" +
                $"\n Is Equal= {object.Equals(ABC_SiteUrl,XYZ_SiteUrl)} ");
            Console.WriteLine();

            ABC_SiteUrl = string.Copy(XYZ_SiteUrl);
            Console.WriteLine("Copy object");
            Console.WriteLine($"After Change 1={ABC_SiteUrl} 2={XYZ_SiteUrl}");
            Console.WriteLine(
                $"Reference  {object.ReferenceEquals(ABC_SiteUrl, XYZ_SiteUrl)}" +
                $"\n Is Equal= {object.Equals(ABC_SiteUrl, XYZ_SiteUrl)} ");
            Console.WriteLine();

            ABC_SiteUrl = XYZ_SiteUrl;
            Console.WriteLine("Assigne Reference");
            Console.WriteLine($"After Change 1={ABC_SiteUrl} 2={XYZ_SiteUrl}");
            Console.WriteLine(
                $"Reference  {object.ReferenceEquals(ABC_SiteUrl, XYZ_SiteUrl)}" +
                $"\n Is Equal= {object.Equals(ABC_SiteUrl, XYZ_SiteUrl)} ");


            Console.ReadLine();
        }
    }


Copy in C#?
It is just get value and paste it into new variable
Reference is different
Required object for coping
Dependence in nature



Constructor Copy
class SiteInfo
    {
        private string SiteDomain { get; }
        private string Sitehots { get; }
        private string Protocal { get; }
        public SiteInfo(string SiteName)
        {
            SiteDomain = SiteName.Split('.')[2];
            Sitehots = SiteName.Split('/').LastOrDefault();
            Protocal = SiteName.Split('/').FirstOrDefault();
        }

        public SiteInfo(SiteInfo info)
        {
            SiteDomain = info.SiteDomain;
            Sitehots = info.Sitehots;
            Protocal = info.Protocal;
        }

        public string ShowData
        {
            get {
return $"Site Domain = {SiteDomain} "+
$"\nSite host={Sitehots}\nProtocal={Protocal}";
 }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
          
string ABC_SiteUrl = "http://www.abc.com";
            string XYZ_SiteUrl = "https://www.xyz.in";

            //Copy constructor
            SiteInfo siteInfo = new SiteInfo(ABC_SiteUrl);
            Console.WriteLine("Site = " + ABC_SiteUrl);
            Console.WriteLine(siteInfo.ShowData);
            Console.WriteLine();

            SiteInfo siteInfocopy = new SiteInfo(siteInfo);
            Console.WriteLine("After copy constructor");
            Console.WriteLine(siteInfocopy.ShowData);
            Console.WriteLine(
                $"Reference= {object.ReferenceEquals(siteInfocopy, siteInfo)}" +
                $"\n Is Equal= {object.Equals(siteInfocopy, siteInfo)}");
            Console.WriteLine();

           
            SiteInfo siteinfos = new SiteInfo(siteInfocopy);
            Console.WriteLine("Copy Constuctor");
            Console.WriteLine(
                $"Reference= {object.ReferenceEquals(siteInfocopy, siteInfo)}" +
                $"\n Is Equal= {object.Equals(siteInfocopy, siteInfo)}");
            Console.WriteLine();

            siteInfo = siteInfocopy;
            Console.WriteLine("Direct Reference");
            Console.WriteLine(
                $"Reference= {object.ReferenceEquals(siteInfocopy, siteInfo)}" +
                $"\n Is Equal= {object.Equals(siteInfocopy, siteInfo)}");
        
            Console.ReadLine();
        }
    }

Interface concept in Programming

Interface Concept in Programming

Concept
Consider the you are the employee of IT company
Company provide you one standard card 
Property of card
1. Shape
2. Placement of words
3. Photo 
4. Info
Above properties are arranged as below format




Just imagine - If employee use different id card shapes and size. it will mess 
to over come this issue and implement standard for all employee we should create interface and implement when we create any employee id card

Key Points 
This is common interface for each and every employee of the company
Can we restrict to use of ID card interface?
No, it will be public by default.
Can we set any name or info directly into the ID card?
No, it will not allow to set into directly, it will just provide frame or structure
you can implement using it. if you try to implement any info, it violate interface property(when interface change all card will get impacted). 

Execution 
We have created the ICard interface
Now we can make any employee card.

interface ICard
{
        string CompanyName { get; set; }
        string FirstName { get; set; }
        string LastName { get; set; }
        string EmployeeID { get; set; }

        string DisplayEmployeeName();
}

//Create ID card for Parmanet employee
class ParmanentEmployeeCard : ICard
{
        public string CompanyName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmployeeID { get; set; }
        public string DisplayEmployeeName()
        {  
            return $"{FirstName} {LastName}";
        }
}
class Program
{
        static void Main(string[] args)
        {
            ICard card = new ParmanentEmployeeCard();
            card.CompanyName = "XYZ Technology";
            card.EmployeeID = "2R451E1542";
            card.FirstName = "Sam";
            card.LastName = "adam";

            Console.WriteLine("Parmanent Employee");
            Console.WriteLine(card.CompanyName);
            Console.WriteLine(card.EmployeeID);                            Console.WriteLine(
                          card.DisplayEmployeeName());
            Console.ReadLine();
        }
    }

Output
Permanent Employee
XYZ Technology
2R451E1542
Sam adam

How we can handle other employee ICard like contract?
This interface will handle it like below

interface ICard
{
        string CompanyName { get; set; }
        string FirstName { get; set; }
        string LastName { get; set; }
        string EmployeeID { get; set; }

        string DisplayEmployeeName();
}

//Create ID card for Parmanet employee
class ParmanentEmployeeCard : ICard
{
        public string CompanyName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmployeeID { get; set; }

        public string DisplayEmployeeName()
        {  
            return $"{FirstName} {LastName}";
        }

//Create ID card for Parmanet employee
class ContractEmployee : ICard
{  
        public string CompanyName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmployeeID { get; set; }

        public string DisplayEmployeeName()
        {
            return $"{FirstName} {LastName}";
        }
}
class Program
{
        static void Main(string[] args)
        {
            ICard card = new ParmanentEmployeeCard();
            card.CompanyName = "XYZ Technology";
            card.EmployeeID = "2R451E1542";
            card.FirstName = "Sam";
            card.LastName = "adam";

            Console.WriteLine("Parmanent Employee");
            Console.WriteLine(card.CompanyName);
            Console.WriteLine(card.EmployeeID);
            Console.WriteLine(
            card.DisplayEmployeeName());


            card = new ContractEmployee();
            card.CompanyName = "XYS Company";
            card.EmployeeID = "2245111654542";
            card.FirstName = "Jonh";
            card.LastName = "Mark";

            Console.WriteLine("\nContract Employee");
            Console.WriteLine(card.CompanyName);
            Console.WriteLine(card.EmployeeID);


            Console.WriteLine(
            card.DisplayEmployeeName()+"\n");
            
            Console.ReadLine();
        }
}

Output
Permanent Employee
XYZ Technology
2R451E1542
Sam adam

Contract Employee
XYS Company
2245111654542
Jonh Mark



Multiple Interfaces

    interface ICard
    {  
        string CompanyName { get; set; }
        string FirstName { get; set; }
        string LastName { get; set; }
        string EmployeeID { get; set; }       
        string DisplayEmployeeName();
    }

    interface ICardTemp
    {
        string VisitorName { get; set; }
        string ContactPerson { get; set; }
    }

//Create ID card for Permanent employee
 class PermanentEmployeeCard : ICard
  {
        public string DisplayEmployeeName()
        {
            return $"{FirstName} {LastName}";
        }
        public string CompanyName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmployeeID { get; set; }
}

class ContractEmployee : ICard, ICardTemp
{
        public string CompanyName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmployeeID { get; set; }
        public string VisitorName { get; set; }
        public string ContactPerson { get; set; }

        public void CreateTempCard()
        {
            Console.WriteLine($"Temp Card \n {VisitorName} \n {ContactPerson}");
        }
        public string DisplayEmployeeName()
        {
            return $"{FirstName} {LastName}";
        }
}

class Program
{
        static void Main(string[] args)
        {
            ICard card = new ParmanentEmployeeCard();
            card.CompanyName = "XYZ Technology";
            card.EmployeeID = "224511542";
            card.FirstName = "Sam";
            card.LastName = "adam";

            Console.WriteLine("Permanent Employee");
            Console.WriteLine(card.CompanyName);
            Console.WriteLine(card.EmployeeID);
            Console.WriteLine(card.DisplayEmployeeName());

            card = new ContractEmployee();
            card.CompanyName = "XYS Company";
            card.EmployeeID = "2245111654542";
            card.FirstName = "Jonh";
            card.LastName = "Mark";

            Console.WriteLine("\nContract Employee");
            Console.WriteLine(card.CompanyName);
            Console.WriteLine(card.EmployeeID);
            Console.WriteLine(card.DisplayEmployeeName()+"\n");

            ContractEmployee Tempcard = new ContractEmployee();
            Tempcard.VisitorName = "Robert";
            Tempcard.ContactPerson = "John Mark";
            Tempcard.CreateTempCard();

            Console.ReadLine();
        }
}

Output
Permanent Employee
XYZ Technology
224511542
Sam adam

Contract Employee
XYS Company
2245111654542
Jonh Mark

Temp Card
 Robert
 John Mark

Errors In Interface


1.Cannot contain fields

interface ICard
{
        string companyName;
}

Output
Error        CS0525        Interfaces cannot contain fields

2. Interface members cannot have a definition


interface ICard
{
        string CompanyName { get; set; }
        string FirstName { get; set; }
        string LastName { get; set; }
        string EmployeeID { get; set; }
        void DisplayName()
        {
            Console.WriteLine($"{FirstName} {LastName}");
        }
        string DisplayEmployeeName();
}

Output
Error        CS0531        'ICard.DisplayName()': interface members cannot have a definition

3.does not implement interface member


interface ICard
{
        string CompanyName { get; set; }
        string FirstName { get; set; }
        string LastName { get; set; }
        string EmployeeID { get; set; }

        string DisplayEmployeeName();
 }

//Create ID card for Parmanet employee
class ParmanentEmployeeCard : ICard
{
        public string CompanyName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmployeeID { get; set; }

       //If you miss any of the method from interface, compile error
       //public string DisplayEmployeeName()
       // {  
       // return $"{FirstName} {LastName}";
        //}
}

Output
Error        CS0535        'ParmanentEmployeeCard' does not implement interface member 'ICard.DisplayEmployeeName()'

**** Sequence doesn't matter for implementation

4.cannot implement an interface member because it is not public



interface ICard
{
        string CompanyName { get; set; }
        string FirstName { get; set; }
        string LastName { get; set; }
        string EmployeeID { get; set; }

        string DisplayEmployeeName();
}

class ParmanentEmployeeCard : ICard
{
      string DisplayEmployeeName()
        {
            return $"{FirstName} {LastName}";
        }
        public string CompanyName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmployeeID { get; set; }
}

Output
Error        CS0737        'ParmanentEmployeeCard' does not implement interface member 'ICard.DisplayEmployeeName()'.
'ParmanentEmployeeCard.DisplayEmployeeName()' cannot   
implement an interface member because it is not public.        


sblog4u. Powered by Blogger.

Topics

Real World Programming Concept in 2 mins

Clone

What is Clone ? It look like duplicate of original Reference is same for string And different for objects Once clone crea...