For some reason, I am having issues with Interfaces. I know a 100 examples have been posted but apparently I’m not smart enough to figure it out…
I have the following interface:
namespace DocStore.Interfaces
{
public interface IResetCategoryControl
{
string CategoryToAdd { set; }
}
}
I want to set CategoryToAdd to a value.
Here is my class that I want to set it in and what I have so far:
public partial class AddDocumentsDialog : IResetCategoryControl
public string CategoryToAdd
{
set
{
IResetCategoryControl() ireset = new IResetCategoryControl();
ireset.CategoryToAdd = value;
}
}
}
What am I doing wrong in the AddDocumentDialog class? I can’t get that part to work.
Thank you!
Eroc
Following line is the problematic one:
First, you need to get rid of first parenthesis:
Next, you cannot instantiate an interface. Interface is only a signature which has to be implemented by a concrete class.
If you are looking at some other people’s code, right click on IResetCategoryControl and select “Find all references” to search if this interface has already been implemented in some class.
For example, you may find:
On the other hand, it looks like you only need to set an internal private field in your setter method. You should do it like this in that case:
But as others have already pointed out, using a write-only property is very unusual, and indicates wrong design.