Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,948 questions

51,890 answers

573 users

How to implement explicit interface in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    interface ISize
    {
        float Height();
        float Width();
    }
    class Program : ISize
    {
        float height;
        float width;

        public Program(float height, float width)
        {
            this.height = height;
            this.width = width;
        }
        // Explicit interface implementation
        float ISize.Height()
        {
            return height;
        }
        // Explicit interface implementation
        float ISize.Width()
        {
            return width;
        }
        static void Main(string[] args)
        {
            Program obj = new Program(3.14f, 5.18f);

            ISize myDimensions = (ISize)obj;
            Console.WriteLine("Height = {0}", myDimensions.Height());
            Console.WriteLine("Width = {0}", myDimensions.Width());
        }
    }
}


/*
run:

Height = 3.14
Width = 5.18

*/

 



answered Apr 27, 2017 by avibootz
edited Apr 27, 2017 by avibootz

Related questions

1 answer 145 views
1 answer 167 views
167 views asked Jan 7, 2016 by avibootz
1 answer 99 views
99 views asked Sep 11, 2020 by avibootz
1 answer 192 views
192 views asked Sep 11, 2020 by avibootz
2 answers 219 views
219 views asked Apr 25, 2017 by avibootz
1 answer 136 views
136 views asked Dec 21, 2016 by avibootz
...