INTERFACE CHANGES

Key points

ISports obj = new Cricket();

Console.WriteLine(obj.CentralHeadQuarter());

				
					
public interface ISports
{
    public string SportsName { get; set; }

    public string CentralHeadQuarter()
    {
        return "DELHI";
    }
}

public class Cricket : ISports
{
    private string _sportsName;
    public string SportsName { get => _sportsName; set => _sportsName = value; }
}

class Program
{
    public static void Main()
    {
        ISports obj = new Cricket();
        //Default methods are accessible through a reference variable of the interface type.
        Console.WriteLine(obj.CentralHeadQuarter());
        Console.ReadKey();
    }
}

				
			

internal string AnnualMeet();

ISports obj = new Cricket();
Console.WriteLine(obj.AnnualMeet());

				
					
public interface ISports
{
    public string SportsName { get; set; }

    public string CentralHeadQuarter()
    {
        return "DELHI";
    }

    internal string AnnualMeet();
}

public class Cricket : ISports
{
    private string _sportsName;
    public string SportsName { get => _sportsName; set => _sportsName = value; }
    string ISports.SportsName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

    string ISports.AnnualMeet()
    {
        return "AT MUMBAI";
    }

    public string AnnualMeet()
    {
        return "AT KOLKOTA";
    }
}

class Program
{
    public static void Main()
    {
        ISports obj = new Cricket();
        Console.WriteLine(obj.AnnualMeet());//calls the first AnnualMeet

        Cricket obj1= new Cricket();//calls the second AnnualMeet
        Console.WriteLine(obj1.AnnualMeet());
        Console.ReadKey();
    }
}

				
			
				
					AT MUMBAI
AT KOLKOTA
				
			

private string AppendHeadQuarter() { return "The HeadQuarter is at:: "; }

				
					
public interface ISports
{
    public string SportsName { get; set; }

    private string AppendHeadQuarter()
    {
        return "The HeadQuarter is at:: ";
    }

    public string CentralHeadQuarter()
    {
        return AppendHeadQuarter() + "DELHI";
    }
}

public class Cricket : ISports
{
    public string SportsName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

    public string AnnualMeet()
    {
        return "AT KOLKOTA";
    }
}

class Program
{
    public static void Main()
    {
        ISports obj = new Cricket();
        Console.WriteLine(obj.CentralHeadQuarter());
        Console.ReadKey();
    }
}

				
			
				
					The HeadQuarter is at:: DELHI
				
			

Console.WriteLine( obj.AppendHeadQuarter()); //you cannot do this

Console.WriteLine( ISports.AppendHeadQuarter()); //you can do this

				
					
public interface ISports
{
    public string SportsName { get; set; }

    internal static string AppendHeadQuarter()
    {
        return "The HeadQuarter is at:: ";
    }

    public string CentralHeadQuarter()
    {
        return AppendHeadQuarter() + "DELHI";
    }
}

public class Cricket : ISports
{
    public string SportsName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

    public string AnnualMeet()
    {
        return "AT KOLKOTA";
    }
}

class Program
{
    public static void Main()
    {
        ISports obj = new Cricket();
        Console.WriteLine(obj.CentralHeadQuarter());
        //Console.WriteLine(obj.AppendHeadQuarter());//you cannot do this
        Console.WriteLine(ISports.AppendHeadQuarter());//you cannot do this
        Console.ReadKey();
    }
}

				
			
				
					The HeadQuarter is at:: DELHI
The HeadQuarter is at::
				
			

Leave a Comment