Compilation Error: "The modifier 'public' is not valid for this item" while creating public method o

Posted by Lalit on Stack Overflow See other posts from Stack Overflow or by Lalit
Published on 2010-04-19T16:17:49Z Indexed on 2010/04/19 16:23 UTC
Read the original article Hit count: 300

Filed under:
|
|

I am getting this error while creating public method on a class for explicitly implementing the interface. I have the workaround: by removing the explicit implementation of PrintName Method, But surprised why i am getting this error.

Can anyone explain the error.

Code for Library: using System; using System.Collections.Generic; using System.Linq; using System.Text;

namespace Test.Lib1
{

    public class Customer : i1 
    {
        public string i1.PrintName() //Error Here...
        {
            return this.GetType().Name + " called from interface i1";
        }
    }

    public interface i1
    {
        string PrintName();
    }

    interface i2
    {
        string PrintName();
    }
}

Code for Console Test Application:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Test.Lib1;

namespace ca1.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Customer customer = new Customer();
            Console.WriteLine(customer.PrintName());

            //i1 i1o = new Customer();
            //Console.WriteLine(i1o.printname());

            //i2 i2o = new Customer();
            //Console.WriteLine(i2o.printname());

        }
    }
}

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#