Thursday, December 29, 2011

Can C# Interfaces have fields

Most of the people answer No to this question. This happens so because which ever thing present in interface has to be Implemented in the class which implemets The Interface.
Here is an Example of this

interface Iclass
    {
        int i { get; set; }
    }

class Class : Iclass
    {

        #region Iclass Members

        public int i
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion
    }



No comments:

Post a Comment