Answers for "interface in c# programiz"

C#
4

creating interface in C#

using System;

namespace Grepper_Docs
{
    public interface IWhatever
    {
        bool doSomething(); //Interface methods don't have bodies or modifiers
    }
  
  	class Program : IWhatever
    {
        static void Main(string[] args)
        {
            var pro = new Program();
            pro.doSomething();
        }

        public bool doSomething() //methods must be public
        {
            return true;
        }
    }
}
Posted by: Guest on August-10-2020
0

interface in c# programiz

using System;
namespace CsharpInterface {

  interface IPolygon {
    // method without body
    void calculateArea(int l, int b);

  }

  class Rectangle : IPolygon {

    // implementation of methods inside interface
    public void calculateArea(int l, int b) {

      int area = l * b;
      Console.WriteLine("Area of Rectangle: " + area);
    }
  }

  class Program {
    static void Main (string [] args) {

      Rectangle r1 = new Rectangle();
    
      r1.calculateArea(100, 200);

    }
  }
}
Posted by: Guest on August-22-2021

Code answers related to "interface in c# programiz"

C# Answers by Framework

Browse Popular Code Answers by Language